如何在Spring MVC中修复“ 400-错误的请求”?

时间:2019-06-01 17:59:42

标签: java mysql spring hibernate

我在Maven中构建了Spring应用程序,当我尝试将表单提交到数据库时,它抛出400-错误的请求错误。我已经通过实体类映射了数据。控制台窗口也不会显示任何错误。

控制器类:

@PostMapping("/saveClient")
    public String saveClients(@ModelAttribute("client") Clients theClients) {

        clientService.saveClient(theClients);

        return "redirect:/clients/list";
    }

DAO类:

@Override
    public void saveClient(Clients theClients) {

        Session currentSession = sessionFactory.getCurrentSession();

        currentSession.saveOrUpdate(theClients);

    }

JSP文件:

<form:form name="NewClient" action="saveClient" modelAttribute="client" method="POST"
onSubmit="return(validate());">

<form:hidden path="id" />

<div class="form-group">
   <label>First Name:</label>
   <form:input type="text" path="firstName" placeholder="First Name"  id="firstName"  class="form-control"/>
</div>
<div class="form-group">
   <label>Last Name:</label>
   <form:input type="text" path="lastName" placeholder="Last Name" id="lastName"  class="form-control"/>
</div>
<div class="form-group">
    <label>Domain:</label>
    <form:select path="domain" class="form-control">
         <form:option value="NONE" label="Select" />
         <form:options items="${domainList}" id="proDomain" />
    </form:select>
 </div>
 <div class="form-group">
    <label>Start Date:</label>
    <form:input type="date" path="startDate" id="projectBeginingDate"
                                    required="required" class="form-control"/>
 </div>
 <div class="form-group">
 <button type="submit" class="btn btn-primary btn-block">Submit</button>
 </div>
 </form:form>

错误:

HTTP Status 400 – Bad Request

Type Status Report

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Apache Tomcat/9.0.16

0 个答案:

没有答案