-1

我在 jstl 的帮助下在 jsp 页面中显示数据时遇到问题。我有代码和错误;我的 JSP 页面是

        <body>
    <table border="1">
        <thead>
                <tr>
                    <th>UserId </th>
                    <th>First Name </th>
                    <th>Last Name </th>
                    <th>DOB </th>
                    <th>Email Id </th>
                    <th colspan="2" >Action</th>
                </tr>
        </thead>
        <tbody>
          <c:forEach items="${users}" var="user" >
             <tr>
                    <td><c:out value="${user.userid}" /></td>
                    <td><c:out value="${user.firstName}" /></td>
                    <td><c:out value="${user.lastName}" /></td>
                    <td><fmt:formatDate pattern="yyyy-MMM-dd" value="${user.dob}" /></td>
                    <td><c:out value="${user.email}" /></td>
                    <td><a href="UserController?action=edit&userId=<c:out value="${user.userid}"/>">Update</a></td>
                    <td><a href="UserController?action=delete&userId=<c:out value="${user.userid}"/>">Delete</a></td>
                </tr>

                </c:forEach>

        </tbody>
    </table>
    <p><a href="UserController?action=insert">Add User</a>

我们获取 ALLUSERLIST IS 的这段代码: public ArrayList getAllUsers() {

ArrayList<User> USER = new ArrayList<User>();
    try
    {
        iduQuery = "select * from user";
        Statement st = conn.createStatement();
        ResultSet rs =st.executeQuery(iduQuery);
        while(rs.next())
        {
            User user =new User();

            user.setUserid(rs.getString("userid"));
            System.out.println("USER ID :    " + user);
            user.setFirstname(rs.getString("firstname"));
            user.setLastname(rs.getString("lastname"));
            user.setDob( new java.sql.Date(rs.getDate("dob").getTime()));
            user.setEmail(rs.getString("email"));
            USER.add(user);
        }

    }catch(Exception e)
    {
            e.printStackTrace();
            System.out.println("Error : GetALLUSER   " + e);
    }
    return USER;

}

我们称之为jsp页面的地方:

            forward ="/listUser.jsp";
            ArrayList<User> myList = new ArrayList<User>();
        myList = userdao.getAllUsers();
        System.out.println("THis List of data arte : " + myList);
        request.setAttribute("users", myList);

并且错误显示:HTTP Status 500 -

org.apache.jasper.JasperException: org.apache.jasper.JasperException: An exception occurred processing JSP page /listUser.jsp at line 33
30:         <tbody>
31:           <c:forEach items="${users}" var="user">
32:              <tr>
33:                     <td><c:out value="${user.userid}" /></td>
34:                     <td><c:out value="${user.firstName}" /></td>
35:                     <td><c:out value="${user.lastName}" /></td>
36:                     <td><fmt:formatDate pattern="yyyy-MMM-dd" value="${user.dob}" /></td>

用户类

    package com.d.model;
import java.util.Date;;

public class User {
    private String userid;
    private String firstName;
    private String lastName;
    private Date dob;
    private String email;

    public String getUserid() {

        return userid;
    }
    public void setUserid(String userid) {

        this.userid = userid;

    }
    /**
     * @return the firstname
     */
    public String getFirstname() {
        return firstName;
    }
    /**
     * @param firstname the firstname to set
     */
    public void setFirstname(String firstName) {
        this.firstName = firstName;

    }
    /**
     * @return the dob
     */
    public Date getDob() {
        return dob;
    }
    /**
     * @param dob the dob to set
     */
    public void setDob(Date dob) {
        this.dob = dob;
    }
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
    /**
     * @return the lastname
     */
    public String getLastname() {
        return lastName;
    }
    /**
     * @param lastname the lastname to set
     */
    public void setLastname(String lastName) {

        this.lastName = lastName;

    }

    @Override
    public String toString() {
        return "User [userid= " + userid + ", firstName= '" + firstName
                + "', lastName=" + lastName + ", dob=" + dob + ", email="
                + email + "]";
    }    
}
4

2 回答 2

2

拼写错误setUsrid.change it setUserid

您正在设置usrid,但您正在访问userid

user.setUsrid(rs.getString("userid")); //usrid

${user.userid} // userid
于 2013-03-18T09:13:23.053 回答
1

拼写错误setUsrid。将其更改为setUserid

您正在设置 usid 但您正在访问用户 ID

user.setUsrid(rs.getString("userid")); //usrid

${user.userid} // userid
于 2014-03-14T05:50:37.260 回答