簡體   English   中英

Spring mvc HTTP 狀態 400 表單提交

[英]Spring mvc HTTP Status 400 form submission

我正在嘗試將一個項目添加到任務列表並提交表單讓我收到錯誤 400 - 客戶端發送的請求在語法上不正確。

Controller 方法

   @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" %>

<form:form method="POST" action="/showAddForm commandName="todo">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM