从JSP页面访问ArrayList

时间:2017-02-20 16:19:05

标签: java jsp servlets arraylist jstl

我正在尝试编写一个简单的支持服务单系统。我有以下代码:

Ticket类:

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类提供由Ticket对象组成的ArrayList。使用该代码,表格内部没有显示任何内容......我已经尝试过不同的技术来访问和显示数据,但无法完成。

1 个答案:

答案 0 :(得分:0)

而不是

 <c:forEach items="${sessionScope.tickets}" var="ticket">

 <c:forEach items="${tickets}" var="ticket">