这是数据访问对象类的代码
public List<UserPojo> viewAllUser(int offset, int noOfRecords)
{
pojo类的代码是
String query ="select SQL_CALC_FOUND_ROWS fname,Id,mname,lname,gender,State from registration limit "+offset+","+noOfRecords;
List<UserPojo> list = new ArrayList<UserPojo>();
UserPojo User = null;
try {
connection = getConnection();
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
User = new UserPojo();
User.SetFname(rs.getString("fname"));
User.Setid(rs.getInt(2));
User.SetMname(rs.getString("mname"));
User.SetLname(rs.getString("lname"));
User.SetGender(rs.getString("gender"));
User.Setstate(rs.getString("State"));
list.add(Fighter);
}
rs.close();
rs = stmt.executeQuery("SELECT FOUND_ROWS()");
if(rs.next())
this.noOfRecords = rs.getInt(1);
} catch (SQLException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}finally
{
try {
if(stmt != null)
stmt.close();
if(connection != null)
connection.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
return list;
}
public String getFname()
{
return fname;
}
public void SetFname(String fname)
{
this.fname = fname;
}
public String getMname()
{
return mname;
}
public void SetMname(String mname)
{
this.mname = mname;
}
public String getLname()
{
return lname;
}
public void SetLname(String lname)
{
this.lname = lname;
}
public String getGender()
{
return gender;
}
public void SetGender(String Per)
{
this.gender = Per;
}
public String getstate()
{
return state;
}
public void Setstate(String state)
{
this.state = state;
}
public int getid()
{
return idm;
}
public void Setid(int m)
{
this.idm=m;
System.out.print(m);
}
}`
Servlet包含以下代码
int page = 1;
int recordsPerPage = 5;
if(request.getParameter("page") != null)
page = Integer.parseInt(request.getParameter("page"));
UserDAO dao = new UserDAO();
List<UserPojo> list = dao.viewAllUser((page-1)*recordsPerPage,recordsPerPage);
int noOfRecords = dao.getNoOfRecords();
int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
request.setAttribute("User", list);
request.setAttribute("noOfPages", noOfPages);
request.setAttribute("currentPage", page);
RequestDispatcher view= request.getRequestDispatcher("DisplayUser.jsp");
view.forward(request, response);
Jsp页面包含代码
<td>${User.gender}</td>
<td>${User.fname} ${User.mname} ${User.lname}</td>
<td>${User.state}</td>
<td>${User.idm}</td>
异常的堆栈跟踪是
type Exception report
消息javax.el.PropertyNotFoundException:在类型FighterPoso上找不到属性'idm'
说明服务器遇到内部错误,导致无法完成此请求。
例外
org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:在类型FighterPoso上找不到属性'idm' org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) FighterServlet.doGet(FighterServlet.java:30) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 根本原因
javax.el.PropertyNotFoundException:在类型FighterPoso上找不到属性'idm' javax.el.BeanELResolver $ BeanProperties.get(BeanELResolver.java:214)
无法理解为什么会发生此异常。因为从jsp页面中删除$ {User.idm}时可以轻松获取所有其他字段。 有一点我想提一下,id字段是具有自动增量功能的数据库中的主键。
答案 0 :(得分:0)
没有任何User.getIdm()方法。 Getter / Setter必须匹配pojo的属性。
还尝试以小写形式启动方法,getter是getXXX,而你的setter是SetXXX,这很难看。
答案 1 :(得分:0)
而不是:
<td>${User.idm}</td>
使用:
<td>${User.id}</td>
您尚未在用户bean中公开getId
方法。
另外请确保遵循java bean命名方案。所以如果你说id为field,那么getter / setter应该是:
.. getId() {
return ...
}
.. setId(..) {
...
}