我有問題在jsp頁面的幫助下顯示jsp頁面中的數據。有代碼,也有我得到的錯誤; 我的JSP頁面如何在jsp中使用jstl arraylist
<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爲: 公衆的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 + "]";
}
}
你沒有顯示你的相關列堆棧跟蹤「usrid」未找到 – PSR 2013-03-18 11:29:32
請刪除此代碼,並顯示現在的代碼 – PSR 2013-03-18 11:30:35
可以顯示異常堆棧跟蹤 – PSR 2013-03-18 11:34:20