Spring mvc Отправка формы статуса HTTP 400 - PullRequest
0 голосов
/ 10 июля 2020

Я пытаюсь добавить элемент в список задач, и отправка формы вызывает ошибку 400 - запрос, отправленный клиентом, был синтаксически неверен.

Метод контроллера

   @RequestMapping(value = "/add-todo", method= RequestMethod.POST)
        public String submitAddForm(ModelMap model , @Valid ToDo todo,  HttpSession httpSession, BindingResult result) {
            System.out.println("running" + result);
            if (result.hasErrors()) {
                System.out.println("ERROR" + result.getAllErrors());
                return "redirect:/showAddForm";
            }
            String user = (String) httpSession.getAttribute("name");
            
            service.addTodo(user, todo.getDescription(), todo.getTargetDate(), false);      
            // Clears the url e.g. name?=jyj123
            model.clear();
            // return to the url which executes the showToDO
            return "redirect:/list-todo";
        }

JSP

<%@ include file = "common/header.jspf" %>
<%@ include file = "common/nav.jspf" %>
    <div class="container">
        <H1>Add your task!</H1>
        <!-- form:form spring MVC container form tag -->
        <!-- commandName is command obj -->
        <form:form method="POST" commandName="todo">
            <!-- fieldset used to group elements in a form. Box elements in one box -->
            <fieldset class="form-group">
            <!-- path links the variable in ToDo.java -->
                <form:label path="description">Description:</form:label> 
                    <!-- required validates nulll -->
                <form:input path="description" type="text" class="form-control" required="required" /> 
                <form:errors path="description" cssClass="text-warning" />
                </fieldset>
                    <fieldset class="form-group">
                <form:label path="targetDate">Target Date</form:label> 
                <form:input path="targetDate" type="date" class="form-control" required="required" /> 
                    <form:errors path="targetDate" cssClass="text-warning" />
                    
            </fieldset>
            
            <button type="submit" class="btn btn-success">Add</button>
        </form:form>
        </div>
    <%@ include file = "common/footer.jspf" %>

1 Ответ

0 голосов
/ 10 июля 2020
<form:form method="POST" action="/showAddForm commandName="todo">
...