【发布时间】:2016-01-22 03:29:04
【问题描述】:
我正在尝试创建一个出现错误的程序
Edit.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:if test="${session_username != null }">Hello ${session_username}!</c:if>
<font face="verdana" size="2">
${welcomeMessage} <BR><BR>
<form:form action="${pageContext.request.contextPath}/editemployee" method="POST" modelAttribute="editForm">
<form:errors path="studenterrors" />
<table>
<tr>
<td colspan="2" align="center">Spring MVC Form Demo - Edit</td>
</tr>
<tr>
<td>User Name</td>
<td><form:input path="username" /></td>
</tr>
<tr>
<td>First Name</td>
<td><form:input path="firstname" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><form:input path="lastname" /></td>
</tr>
<tr>
<td>Mobile No.</td>
<td><form:input path="mobileno" /></td>
</tr>
<tr>
<td>Password</td>
<td><form:password path="password" /></td>
</tr>
<tr>
<td>Email</td>
<td><form:input path="email" /></td>
</tr>
<tr>
<td>BirthDate (mm/dd/yyyy)</td>
<td><form:input path="birthdate" /></td>
</tr>
<tr>
<td>Profession</td>
<td><form:select path="profession" items="${professionList}" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</font>
</body>
</html>
登录成功.java
package java4s;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java4s.EmployeeService;
@Controller
public class LoginSuccessController {
@Autowired
EmployeeService emp_service;
@RequestMapping(value = "/editemployee", method=RequestMethod.POST)
public ModelAndView EditSaveMyInfo(ModelMap model, @ModelAttribute("editForm") Employee employee) {
model.addAttribute("message", "Information Updated");
return new ModelAndView("EditSuccess",model);
}
}
每当我点击提交按钮时,我都会收到HTTP Status 400 - 错误。但是当我从函数EditSaveMyInfo 中删除@ModelAttribute("editForm") Employee employee 时,不会出现错误?
我该如何解决这个错误?
编辑
Employee.java
package java4s;
import java.util.Date;
public class Employee {
private String userid;
private String firstname;
private String lastname;
private String mobileno;
private String username;
private String password;
private String email;
private Date birthDate;
private String profession;
private String studenterrors;
public String getUserid()
{
return userid;
}
public void setUserid(String userid)
{
this.userid = userid;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getFirstname()
{
return firstname;
}
public void setFirstname(String firstname)
{
this.firstname = firstname;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String lastname)
{
this.lastname = lastname;
}
public String getMobileno()
{
return mobileno;
}
public void setMobileno(String mobileno)
{
this.mobileno = mobileno;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public Date getBirthdate()
{
return birthDate;
}
public void setBirthdate(Date birthDate)
{
this.birthDate = birthDate;
}
public String getProfession()
{
return profession;
}
public void setProfession(String profession)
{
this.profession = profession;
}
public String getstudenterrors()
{
return studenterrors;
}
public void setstudenterrors(String studenterrors)
{
this.studenterrors = studenterrors;
}
}
【问题讨论】:
-
你能分享一下编辑表格吗
-
你的意思是
EditSuccess.jsp页面? -
@AjmalMuhammad,更新了代码。
-
@HarshitShrivastava 您得到的确切错误跟踪是什么?我无法使用您的代码重现错误,并且无法查看我的
EditSuccess页面 -
@TimeTravel,当我删除
<form:input path="birthdate" />时,它工作正常。错误描述为The request sent by the client was syntactically incorrect
标签: java spring jsp spring-mvc