2017-04-21 38 views
1

保存結果集的結果我無法完成,我正在做一個web應用程序的功能。ArrayList中

下面的代碼appearently沒有產生任何錯誤,

//This is the trouver (find) function, code is related to DAO pattern. 
    public ArrayList<Ticket> trouver(int id_employe) throws DAOException { 
    ArrayList<Ticket> liste = new ArrayList<Ticket>(); 
    Connection connexion = null; 
    PreparedStatement preparedStatement = null; 
    ResultSet resultSet = null; 
    Ticket ticket = null; 

    try { 
     connexion = daoFactory.getConnection(); 
     preparedStatement = initialisationRequetePreparee(connexion, SQL_SELECT_PAR_EMP, false, id_employe); 
     resultSet = preparedStatement.executeQuery(); 

     if (resultSet.next()) { 
      ticket = map(resultSet);//map function stores a row's result in a Bean. 
      liste.add(ticket); 
     } 
    } catch (SQLException e) { 
     throw new DAOException(e); 
    } finally { 
     fermeturesSilencieuses(resultSet, preparedStatement, connexion); 
    } 
    return liste; 
} 

通過servlet:

ArrayList<Ticket> lticket = ticketform.recupererTicket(request); 
request.setAttribute("lticket", lticket); 
this.getServletContext().getRequestDispatcher(VUE).forward(request, response); 

錯誤開始顯示出來,當談到的觀點:

org.apache.jasper.JasperException: An exception occurred processing JSP page /ListeTickets.jsp at line 29 
26: </tr> 
27: <c:forEach items="${ requestScope.lticket }" var="mapticket"> 
28: <tr> 
29: <c:forEach items="${mapticket}" var="ticket"> 
30: <td><c:out value="${ ticket.sujet }"/></td> 
31: <td><c:out value="${ ticket.description }"/></td> 
32: <td><c:out value="${ ticket.priorite }"/></td> 
Stacktrace: 
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) 

長話短說,我有存儲在ArrayList中豆類的列表,需要兩個循環遍歷整個數據,但出現錯誤。

回答

3

應該只有一個forEach根據你的代碼是:

<c:forEach items="${ lticket }" var="ticket"> 
<tr> 
<td><c:out value="${ ticket.sujet }"/></td> 
<td><c:out value="${ ticket.description }"/></td> 
<td><c:out value="${ ticket.priorite }"/></td> 
</tr> 
</c:forEach> 
+0

當然...謝謝你亞歷克斯。 可悲的是它返回,但只有一個「票」 http://hpics.li/6cc6741 http://hpics.li/b9ffdb5 – TheNorth

+0

能否請您確認,如果這是如何存儲SQL結果集? '嘗試{ 的resultSet = preparedStatement.executeQuery(); 如果(resultSet.next()){ 票=地圖(的resultSet); //映射函數存儲行的結果在一個Bean。 liste.add(ticket); } }' – TheNorth

+0

我想你想用'((resultSet.next))',而不是'if'。 – Alex