0
votes

This is the code of Data Access object class

public List<UserPojo> viewAllUser(int offset, int noOfRecords) {
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; }
code for pojo class is

    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 contains the code below

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);

The Jsp Page contains the code

            <td>${User.gender}</td>
            <td>${User.fname} ${User.mname} ${User.lname}</td>
            <td>${User.state}</td>
            <td>${User.idm}</td>

The stack trace of the exception is

type Exception report

message javax.el.PropertyNotFoundException: Property 'idm' not found on type FighterPoso

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property 'idm' not found on type FighterPoso 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) root cause

javax.el.PropertyNotFoundException: Property 'idm' not found on type FighterPoso javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)

Unable to understand why this exception is happening. Because all other fields are easily fetched when ${User.idm} is removed from the jsp page. One thing i would like to mention that the id field is the primary key in the database with autoincrement feature.

2

2 Answers

0
votes

Instead of :

<td>${User.idm}</td>

Use:

<td>${User.id}</td>

You haven't exposed getId method in your user bean.

Also please ensure you follow java bean naming scheme. So if you have say id as field then getter/setter should be like:

 .. getId() {
    return ...
 }

 .. setId(..) {
     ...
 }
0
votes

There isn't any User.getIdm() method. The Getter/Setter must match the pojo's attribute.

Also try to start methods in lowercase, your getters are getXXX and your setters are SetXXX, that's ugly.