我是Spring MVC的新手,并且因为javax.el.PropertyNotFoundException的错误而有点迷失,我目前在第一个测试应用程序中遇到这个错误。 我正在尝试显示一个人员列表,然后按一个按钮进入新页面,询问新的人员详细信息。
所以我得到了人物模型
public class Person {
private String firstName;
private String lastName;
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;
}
}
每当用户要求输入一个人的新条目时,就会调用addPersonInitial方法。此后,当用户填写表单时,提交由addPersonFinal函数处理。该函数应添加新条目并重定向回页面,该页面显示已存在的人员列表。
@Controller
@RequestMapping(value="person")
public class PersonController{
@Autowired
private PersonService personservice;
@RequestMapping(value="viewAll", method=RequestMethod.GET)
public ModelAndView viewAll() {
ModelAndView mav = new ModelAndView();
mav.setViewName("viewAll");
mav.addObject("persons", personservice.getAllPersons());
return mav;
}
@RequestMapping(value="addPersonInitial", method = RequestMethod.GET)
public ModelAndView addPersonInitial() {
ModelAndView mav = new ModelAndView();
mav.setViewName("addPersonInitial");
mav.addObject("person", new Person());
return mav;
}
@RequestMapping(value="addPersonFinal", method = RequestMethod.POST)
public ModelAndView addPersonFinal(@ModelAttribute(value="person") Person person) {
this.personservice.addPerson(person);
return this.viewAll();
}
}
jsp中的代码是
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Person Initial</title>
</head>
<body>
<table>
<tbody>
<form:form method="POST" action="addPersonFinal" commandName="person">
<tr>
<td><label for="firstName">First Name: </label><form:input path= "firstName" /> </td>
<td><label for="lastName">Last Name: </label><form:input path="lastName" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Add" /></td>
</tr>
</form:form>
</tbody>
</table>
</body>
</html>
当用户提交新用户的表单数据时,我收到以下错误
输入例外报告
message javax.el.PropertyNotFoundException:在类型net.viralpatel.spring3.model.Person上找不到属性'FirstName'
说明服务器遇到内部错误,导致无法完成此请求。
例外
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property 'FirstName' not found on type net.viralpatel.spring3.model.Person
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)`enter code here`