gpt4 book ai didi

java - webapp 中的异常,即org.apache.jasper.JasperException

转载 作者:行者123 更新时间:2023-12-01 19:48:58 26 4
gpt4 key购买 nike

我构建了一个 dao 层,它使用 jdbctemplate 与 derby 数据库连接。

插入查询工作正常,但是当我尝试从数据库中选择所有行时,网络应用程序给我这个错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/DisplayEmployee.jsp at line 26

23: 24: 25: 26: ${temp.FirstName} 27: ${temp.MiddleName} 28: ${temp.LastName} 29: ${temp.email}

avax.el.PropertyNotFoundException: Property 'FirstName' not found on type com.user.EmployeeInfo

enter image description here

代码:

DAO:

public class EmployeeDao {
JdbcTemplate template;
public void setTemplate(JdbcTemplate template) {
this.template = template;
}
public int insert(EmployeeInfo emp){

String sql = "insert into employee VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
int i=template.update(sql, emp.getFirstName(), emp.getMiddleName(), emp.getLastName(), emp.getEmail(), emp.getGender(), emp.getDob(), emp.getAddress1(), emp.getAddress2(), emp.getEmpID());
return i;
}

public List<EmployeeInfo> retrieveMultipleRowsColumns(){
String sql = "select * from employee";
//return template.queryForList(sql, elementType)
//List<EmployeeInfo> list = template.query(sql,new BeanPropertyRowMapper<EmployeeInfo>(EmployeeInfo.class));
//List<EmployeeInfo> list2 = template.queryForList(sql, EmployeeInfo.class);
List<EmployeeInfo> list3 = template.query(sql, new RowMapper<EmployeeInfo>(){
public EmployeeInfo mapRow(ResultSet rs, int rownumber) throws SQLException {
EmployeeInfo e = new EmployeeInfo();
e.setFirstName(rs.getString(1));
e.setMiddleName(rs.getString(2));
e.setLastName(rs.getString(3));
e.setEmail(rs.getString(4));
e.setGender(rs.getString(5));
e.setDob(rs.getDate(6));
e.setAddress1(rs.getString(7));
e.setAddress2(rs.getString(8));
e.setEmpID(rs.getInt(9));
return e;
}
});
return list3;
}

Controller :

public class EmployeeAddition {  
@Autowired
EmployeeDao dao;
@RequestMapping("/addresult")
public ModelAndView addResult(HttpServletRequest req,HttpServletResponse res) {

String fname = req.getParameter("FirstName");
String mname = req.getParameter("MiddleName");
String middlename;
if(mname!="null"&&mname.trim()!=""){
middlename=mname;
}
else
{
middlename="-";
}
String lname = req.getParameter("LastName");
String empid = req.getParameter("empID");
int empID = Integer.parseInt(empid);
String email = req.getParameter("Email");
String gender = req.getParameter("gender");
Date dob = Date.valueOf(req.getParameter("DOB"));
String addr1 = req.getParameter("address1");
String addr2 = req.getParameter("address2");
EmployeeInfo emp = new EmployeeInfo(fname,middlename,lname,email,gender,dob,addr1,addr2,empID);
int ret = dao.insert(emp);

if(ret==0){
return new ModelAndView("EmployeeAddResult","mess","Success");
}
else
{
return new ModelAndView("EmployeeAddResult","mess","hi");
}
}
@RequestMapping("/display")
public ModelAndView viewEmployee(HttpServletRequest req,HttpServletResponse res,ModelMap model) {
List<EmployeeInfo> list=dao.retrieveMultipleRowsColumns();
model.put("list",list);
return new ModelAndView("DisplayEmployee","mess","Welcome "+(String)req.getSession().getAttribute("uname"));
}
}

我显示结果的jsp:

<div class="right_disp left">
<c:forEach items="${list}" var="temp">
<tr>
<td>${temp.FirstName}</td>
<td>${temp.MiddleName}</td>
<td>${temp.LastName}</td>
<td>${temp.email}</td>
<td>${temp.gender}</td>
<td>${temp.dob}</td>
<td>${temp.Address1}</td>
<td>${temp.Address2}</td>
<td>${temp.empID}</td>
</tr>
</c:forEach>
</div>

变量名与POJO类的原始变量匹配,但我不明白为什么会出现Property not find on the class的错误。

感谢任何建议或帮助。

编辑:

EmployeeInfo 类(POJO)

import java.sql.Date;

public class EmployeeInfo {
String FirstName;
String MiddleName;
String LastName;
String email;
String gender;
Date dob;
String Address1;
String Address2;
int empID;

public EmployeeInfo(){

}

public EmployeeInfo(String firstName, String middleName, String lastName, String email, String gender,
Date dob, String address1, String address2, int empID) {
super();
FirstName = firstName;
MiddleName = middleName;
LastName = lastName;
this.email = email;
this.gender = gender;
this.dob = dob;
Address1 = address1;
Address2 = address2;
this.empID = empID;
}

public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getMiddleName() {
return MiddleName;
}
public void setMiddleName(String middleName) {
MiddleName = middleName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getAddress1() {
return Address1;
}
public void setAddress1(String address1) {
Address1 = address1;
}
public String getAddress2() {
return Address2;
}
public void setAddress2(String address2) {
Address2 = address2;
}
public int getEmpID() {
return empID;
}
public void setEmpID(int empID) {
this.empID = empID;
}

}

最佳答案

如果属性名称遵循 bean 属性命名约定,则不要将其首字母大写。

如果您的 getter 和 setter 名为 getSomePropertysetSomeProperty,那么在模板中您应该使用 someProperty 而不是 SomeProperty >.

关于java - webapp 中的异常,即org.apache.jasper.JasperException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52176533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com