【问题标题】:Spring mvc HTTP Status 400 form submissionSpring mvc HTTP状态400表单提交
【发布时间】:2020-10-31 09:12:51
【问题描述】:

我正在尝试将一个项目添加到任务列表中,提交表单时收到错误 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" %>

【问题讨论】:

  • @MinarMahmud addToDo

标签: java spring spring-mvc web-applications


【解决方案1】:
<form:form method="POST" action="/showAddForm commandName="todo">

【讨论】:

  • 新代码抛出 org.apache.jasper.JasperException
猜你喜欢
  • 2017-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 1970-01-01
  • 2021-01-01
  • 2019-09-18
相关资源
最近更新 更多