简体   繁体   中英

Accessing ArrayList from JSP page

I'm trying to code a simple support ticket system. I have the following code:

The Ticket class:

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);  
}

And finally the jsp file were I'm trying to display the data of the tickets.

<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>

The UserDAO class used in the Servlet provides an ArrayList formed by Ticket objects. With that code the table shows nothing inside... I have already tried different techniques for accesing and displaying the data but can't get it done.

Instead of

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

try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM