print a list returned from the servlet in a jsp

0

Good morning, guys I'm killing myself to make my jsp return a list that comes from the DB, I'm getting the information from the bank and I can launch from the 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> it brings everyone on the same line and not one below the other.

Could you 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);

        }
    
asked by anonymous 02.03.2018 / 15:36

2 answers

0

Thanks for the help, man, I've found a way to solve it.

  <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>
    
07.03.2018 / 21:27
0

You need to retrieve the properties of your System object individually for each column. In your example 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 set in var has an object inserted in your list . For each object, you will need to retrieve the value of each property.

    
02.03.2018 / 17:21