print a returned Servlet list in a jsp

Asked

Viewed 238 times

0

Good morning, guys I’m killing myself to make my jsp return a list that comes from the BD, I’m taking the information from the bank and I can launch from Servlet to the jsp but not in an orderly and dynamic way, ends up pulling all the items in the same row, not in table form.<tr> <td><% out.print(obj.getSitema());%></td></tr> he brings all in the same line and not one below the other.

could help me

> JSP


   <body>

        <% incidenteDao inci = new incidenteDao();
            Sistema sist = new Sistema();
            for (Iterator it = inci.listaIncidentes().iterator(); it.hasNext();) {
                obj = (Sistema) it.next(); %>  
    <tr> 
        <td><% out.print(obj.getSitema());%></td>
    <tr>


<c:forEach var="lista" items="${lista}">
    <tr>
      <td><% out.print(obj.getSitema());%></td>

    </tr>
  </c:forEach>


> SERVLET

      incidenteDao inciDao = new incidenteDao();
            Sistema sistema = null;
            List<Sistema> listas = inciDao.listaIncidentes();

            request.setAttribute("listas", listas);
            RequestDispatcher rd = request.getRequestDispatcher("teste.jsp");
            rd.forward(request, response);

        }

2 answers

0


Thanks for the help man, I found a way to solve

  <table class="table" id="tbInci">
                        <tr> 
                            <th>Ocorrência</th>
                            <th>Sistema</th>
                            <th>Horario abertura </th>
                            <th>numero do chamado</th>
                            <th>Status</th>
                        </tr>
                        <% incidenteDao inciDao = new incidenteDao();

                            List<Sistema> incidentes = inciDao.listaIncidentes();

                            for (Sistema s : incidentes) {

                        %>
                        <tr>
                            <td> <%=s.getOcorrencia()%></td>   
                            <td> <%=s.getSitema()%></td>
                            <td> <%=s.getAbertura()%></td>
                            <td><%=s.getChamado()%></td>
                            <td> <%=s.getStatus()%><br></td>
                        </tr>
                        <%}%>
                    </table>

0

You need to recover the properties of your object System individually for each column. In your example it would be something like:

<c:forEach var="obj" items="${lista}">
  <tr>
     <td>${obj.propriedade1}</td>
     <td>${obj.propriedade2}</td>
     <td>${obj.propriedade3}</td>
     <td>${obj.propriedade4}</td>
  </tr>
</c:forEach>

The value defined in var has an object inserted in its list. For each object, you will need to recover the value of each property.

  • Maybe I misunderstood, but I did it right. Unfortunately it did not work colleague that is the return of my bank >> voltar web systems systems systems }, because if I repeat the process will repeat the same line, with all the contents of the list, not one by one for some reason it is not possible to pull also the Dice

  • I also tried this but did not list anything on the jsp & #Xa; <c:foreach var="lists" items="${lists}"> <tr> <td>${lists.system}</td> </tr> </c:foreach>

  • I edited my answer, see if it helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.