2017-03-04 67 views
0

我得到HTTP状态400.客户端发送的请求在语法上不正确。我所做的只是将编辑表单保存到数据库中,但请求不要去saveApplication方法。提供HTTP状态的Spring MVC表单400

以下是我的edit.jsp

<div align="center"> 
     <h1>New/Edit Contact</h1> 
     <form:form action="saveApplication" method="post" modelAttribute="application"> 
     <table> 
      <form:hidden path="applicationId"/> 
      <tr> 
       <td>Application Name:</td> 
       <td><form:input path="applicationName" /></td> 
      </tr> 
      <tr> 
       <td>Start Date:</td> 
       <td><form:input path="startDate" id="startDate"/></td> 
      </tr> 
      <tr> 
       <td>End Date:</td> 
       <td><form:input path="endDate" id="endDate"/></td> 
      </tr> 
      <tr> 
       <td>Projected StartDate:</td> 
       <td><form:input path="projectedStartDate" id="projectedStartDate"/></td> 
      </tr> 
      <tr> 
       <td>Projected EndDate:</td> 
       <td><form:input path="projectedEndDate" id="projectedEndDate"/></td> 
      </tr> 
      <tr> 
       <td>Current Action:</td> 
       <td><form:input path="currentAction" /></td> 
      </tr> 

      <tr> 
       <td>Comments:</td> 
       <td><form:input path="comments" /></td> 
      </tr> 
      <tr> 
       <td colspan="2" align="center"><input type="submit" value="Save"></td> 
      </tr> 
     </table> 
     </form:form> 
    </div> 

在我的控制器类了以下方法:

@RequestMapping(value = "/editApplication", method = RequestMethod.GET) 
    public ModelAndView editApplication(HttpServletRequest request) { 

     ModelAndView model = new ModelAndView(); 
     int applicationId = Integer.parseInt(request.getParameter("id")); 
     ApplicationTO to = applicationService.getApplication(applicationId); 
     model.addObject("application", to); 
     model.setViewName("edit"); 

     return model; 
    } 

    @RequestMapping(value = "/saveApplication", method = RequestMethod.POST) 
    public ModelAndView saveContact(@ModelAttribute ApplicationTO application) { 
     ModelAndView model = new ModelAndView(); 
     applicationService.saveApplication(application); 
     model.setViewName("view"); 
     return model; 
    } 

回答

-1

尝试将斜线动作名称的东西像现在这样

<form:form action="/saveApplication" method="post" modelAttribute="application"> <table> 

这可能是必需的。

同时检查提交表单时浏览器栏上打印的URL。仔细检查路径是你的控制器所期待的。

+0

我上面一个,其给HTTP状态试图404 -/saveApplication – ASR

+0

其给予theurl像这样,当我提交的http://本地主机:8080/saveApplication(对于上述溶液中)和它不表示任何日志 – ASR

+0

Spring使用强大的命名约定......你可以尝试在控制器内而不是应用程序中使用applicationId吗? – OEH

1

我错过了表单中的变量danoneValidation,实际上这个变量存在于Model类中。

<div align="center"> 
      <h1>New/Edit Contact</h1> 
      <form:form action="saveApplication" method="post" modelAttribute="application"> 
      <table> 
       <form:hidden path="applicationId"/> 
       <tr> 
        <td>Application Name:</td> 
        <td><form:input path="applicationName" /></td> 
       </tr> 
       <tr> 
        <td>Start Date:</td> 
        <td><form:input path="startDate" id="startDate"/></td> 
       </tr> 
       <tr> 
        <td>End Date:</td> 
        <td><form:input path="endDate" id="endDate"/></td> 
       </tr> 
       <tr> 
        <td>Projected StartDate:</td> 
        <td><form:input path="projectedStartDate" id="projectedStartDate"/></td> 
       </tr> 
       <tr> 
        <td>Projected EndDate:</td> 
        <td><form:input path="projectedEndDate" id="projectedEndDate"/></td> 
       </tr> 
       <tr> 
        <td>Current Action:</td> 
        <td><form:input path="currentAction" /></td> 
       </tr> 

       <tr> 
        <td>Danone Validation:</td> 
        <td><form:input path="danoneValidation" /></td> 
       </tr> 

       <tr> 
        <td>Comments:</td> 
        <td><form:input path="comments" /></td> 
       </tr> 
       <tr> 
        <td colspan="2" align="center"><input type="submit" value="Save"></td> 
       </tr> 
      </table> 
      </form:form> 
     </div>