我编写了一个程序来显示在另一个表单中输入的一些细节。就像我有一个UserRegisteration.jsp,我输入的一些细节和UserAccount.jsp,它必须显示一些输入的细节。我创建了一个模型对象UserDetails,包含特定代码的所有详细信息。 当我运行项目时,我得到了propertynotfound异常。我检查了所有内容,无法找到它背后的原因。我的模型类中有getter和setter方法。并使用@modelattribute使用自动绑定功能如果我错过任何代码,请告诉我。
UserDetails.java
package com.bindu.myBankcontroller;
import java.util.ArrayList;
public class UserDetails {
private String UserName;
private String FirstName;
private String LastName;
private String EmailId;
private ArrayList<String> AccountType;
private ArrayList<String> gender;
private Long AccountNo;
private int age;
private String password;
Address address;
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public String getEmailId() {
return EmailId;
}
public void setEmailId(String emailId) {
EmailId = emailId;
}
public ArrayList<String> getAccountType() {
return AccountType;
}
public void setAccountType(ArrayList<String> accountType) {
AccountType = accountType;
}
public ArrayList<String> getGender() {
return gender;
}
public void setGender(ArrayList<String> gender) {
this.gender = gender;
}
public Long getAccountNo() {
return AccountNo;
}
public void setAccountNo(Long accountNo) {
AccountNo = accountNo;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
Controller类,UserAccountController.java
package com.bindu.myBankcontroller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.web.servlet.ModelAndView;
import com.bindu.myBankcontroller.UserDetails;
@Controller
public class UserAccountController {
@ModelAttribute
public void addingCommonObjects(Model model1) {
model1.addAttribute("headerMessage", "MyBank, India");
}
@RequestMapping(value="/LoginForm.html", method = RequestMethod.GET)
public ModelAndView getAdmissionForm() {
ModelAndView model1 = new ModelAndView("LoginForm");
return model1;
}
@RequestMapping(value="/userRegistration.html", method = RequestMethod.GET)
public ModelAndView submitRegistrationForm() {
ModelAndView model1 = new ModelAndView("UserRegistration");
return model1;
}
@RequestMapping(value="/UserAccount.html", method = RequestMethod.POST)
public ModelAndView userAccountForm(@ModelAttribute("user") UserDetails user) {
System.out.println("User name:"+user.getUserName());
ModelAndView model1 = new ModelAndView("UserAccount");
return model1;
}
}
UserAccount.jsp
<html>
<body>
<h1>${headerMessage}</h1>
<h3>Congratulations!! you have successfully registered</h3>
<h2>Details submitted by you:: </h2>
<table>
<tr>
<td>User Name :</td>
<td>${user.UserName}</td>
</tr>
<tr>
<td>First Name :</td>
<td>${user.FirstName}</td>
</tr>
<tr>
<td>Last Name :</td>
<td>${user.LastName}</td>
</tr>
</table>
</body>
</html>
所有相关帖子都没有帮助我解决这个问题,所以我发布了这个帖子。
答案 0 :(得分:4)
问题是由于您在jsp中访问属性的方式,
${user.UserName}
应该是
${user.userName}
对于其他表达式,你应该小写第一个字母。
在幕后花了 UserDetails 并且创建了属性地图,但是这些键基于你的getter / setter方法,因此是小写的(userName,firstName,lastName)。在您的JSP EL中,您传递了密钥,并且由于大小写差异而无法匹配任何属性
答案 1 :(得分:0)
您的实例变量不遵守Java命名原则。 Java变量应以较低的字母开头并使用驼峰大小写。
Ex: userName,firstName,lastName , 相应的getter将是 getUserName(),getFirstName(),getLastName()。
如果您具有这样定义的实例变量,则将通过剥离 get (或是,如果方法)获取jsp 访问者返回一个布尔值)后缀并降低剩余方法名称的第一个字母: $ {user.userName},$ {user.firstName},$ {user.lastName} 。