我試圖編寫一個簡單的支持票證系統。我有以下代碼:從JSP頁面訪問ArrayList
售票類:
public class Ticket implements Serializable{
private static final long serialVersionUID = -4585877638895523067L;
private int ticketID;
private int userID;
private String topic;
private String desc;
private String category;
private int state;
private String answer;
public Ticket(int ID, int userID, String topic, String desc, String category, int state, String answer){
this.ticketID = ID;
this.userID = userID;
this.topic = topic;
this.desc = desc;
this.category = category;
this.state = state;
this.answer = answer;
}
public int getTicketid() {
return ticketID;
}
public int getUserid() {
return userID;
}
public String getTopic() {
return topic;
}
public String getDesc() {
return desc;
}
public String getCategory() {
return category;
}
public int getState() {
return state;
}
public String getAnswer() {
return answer;
}
}
的Servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
session = request.getSession(true);
String action = request.getParameter("action");
RequestDispatcher dispatcher;
if (session.getAttribute("isLoged") == null || session.getAttribute("isLoged").equals(false)) {
dispatcher = getServletContext().getRequestDispatcher("/Login");
}else{
du = new DAOUser();
ticketlist = du.getTickets((Integer)session.getAttribute("userid"));
session.setAttribute("tickets", ticketlist);
dispatcher = getServletContext().getRequestDispatcher("/account.jsp");
if(action!=null){
}
}
dispatcher.forward(request, response);
}
最後的JSP文件中我想要顯示的數據門票。
<tbody>
<c:forEach items="${sessionScope.tickets}" var="ticket">
<tr>
<td>${ticket.ticketID}</td>
<td>${ticket.topic}</td>
<td>${ticket.category}</td>
<td>${ticket.status}</td>
</tr>
</c:forEach>
</tbody>
在Servlet使用的UserDAO的類提供通過票務對象形成的ArrayList
。有了這個代碼,表格裏面什麼都沒有顯示......我已經嘗試了不同的技術來訪問和顯示數據,但無法完成。
是否檢查ticketlist是不是空的? – mlg