0

我是 Spring MVC 的新手,对我目前在我的第一个测试应用程序中遇到的 javax.el.PropertyNotFoundException 错误有点迷失。我正在尝试显示人员列表,然后按下按钮进入一个新页面,该页面要求输入新的人员详细信息。

所以我得到了 Person 模型

    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>

当用户为新用户提交表单数据时,我收到以下错误

类型异常报告

消息 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`
4

0 回答 0