[英]In SpringMVC, after form is submitted, PropertyNotFoundException Encountered
這是控制器 。
@Controller
@RequestMapping("/Register")
public class RegistrationController {
@RequestMapping(method=RequestMethod.GET)
public String showForm(ModelMap model)
{
System.out.println("..In showform()..");
UserBean userbean=new UserBean();
model.addAttribute("USER", userbean);
return "Test";
}
@RequestMapping(value="/Register" ,method=RequestMethod.POST)
public String processForm(@ModelAttribute("USER") UserBean user)
{
System.out.println("UserDetails are :"+ user.getFirstName());
System.out.println("UserDetails are :"+ user.getAge());
return "Success";
}
}
這是Test.jsp
<form:form method="POST" modelAttribute="USER" action="Register">
<table>
<tr><td>Name</td> <td><form:input path="FirstName"/></td></tr>
<tr><td>Age</td> <td><form:input path="Age"/></td></tr>
<tr><td><input type="submit" value="Submit"/></td></tr>
</table>
</form:form>
這是Success.jsp
<body>
<table>
<tr>
<td>User Name :</td>
<td><core:out value="${USER.FirstName}" /></td>
</tr>
<tr>
<td>Age :</td>
<td><core:out value="${USER.Age}" /></td>
</tr>
</table>
</body>
這是com.beans.UserBean
public class UserBean {
private String FirstName;
private int Age;
public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
this.FirstName = firstName;
}
public int getAge() {
return Age;
}
public void setAge(int age) {
this.Age = age;
}
}
現在,我點擊“提交”按鈕后,遇到以下錯誤。 不知道為什么。 我在表單支持bean中有適當的getter / setter。
javax.el.PropertyNotFoundException: Property 'FirstName' not found on type com.beans.UserBean
private String FirstName;
private int Age;
這確實是一個壞習慣,用小寫字母定義變量中的第一個字符。 使其小寫,然后重試。
將您的屬性重命名為具有較低f的firstName
。 由於命名約定,請重試(也在jsp中)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.