我有问题在jstl的帮助下在jsp页面中显示数据。我有代码和错误; 我的JSP PAGE是
<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状态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>
User.class
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 + "]";
}
}
答案 0 :(得分:2)
拼写错误setUsrid
。将其更改为setUserid
您正在设置usrid
,但您正在访问userid
user.setUsrid(rs.getString("userid")); //usrid
${user.userid} // userid
答案 1 :(得分:1)
拼写错误setUsrid
。将其更改为setUserid
您正在设置usrid,但您正在访问userid
user.setUsrid(rs.getString("userid")); //usrid
${user.userid} // userid