@WebServlet("/pedidos") public class PedidosServlet extends HttpServlet{ private Pedidos…
- User
@WebServlet("/pedidos")
public class PedidosServlet extends HttpServlet{
private Pedidos pedidoWS = new Pedidos();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
codethrows ServletException, IOException { HttpSession session = request.getSession(false); if (session == null || session.getAttribute("USER") == null) { // Redirige al login.jsp si el usuario no está logueado response.sendRedirect("index.jsp"); return; // termina el método aquí } // Llamada al método que consume el servicio web y obtiene los pedidos List<pe.company.ws.PedidoVO> pedidos = pedidoWS.listar(); //response.setContentType("text/html;charset=UTF-8"); StringBuilder htmlTable = new StringBuilder(); try { // Comienzo del HTML htmlTable.append("<table class='table' id='listarPedidos'>"); // Corregir typo en “class” htmlTable.append("<thead>"); htmlTable.append("<tr>"); htmlTable.append("<th>Código</th>"); htmlTable.append("<th>Descripcion</th>"); // Mantener consistencia en la escritura htmlTable.append("<th>Estado</th>"); htmlTable.append("<th>Monto total</th>"); htmlTable.append("<th>ID Usuario</th>"); htmlTable.append("</tr>"); htmlTable.append("</thead>"); htmlTable.append("<tbody>"); // Bucle para llenar la tabla con los datos for (pe.company.ws.PedidoVO pedido : pedidos) { htmlTable.append("<tr>"); htmlTable.append("<td>").append(pedido.getIdPedido()).append("</td>"); htmlTable.append("<td>").append(pedido.getDescripcion()).append("</td>"); htmlTable.append("<td>").append(pedido.getEstado()).append("</td>"); // Asumiendo que estas propiedades existen en tu clase PedidoVO htmlTable.append("<td>").append(pedido.getMontoTotal()).append("</td>"); htmlTable.append("<td>").append(pedido.getUsaurio().getIdUsuario()).append("</td>"); htmlTable.append("</tr>"); } // Fin del HTML htmlTable.append("</tbody>"); htmlTable.append("</table>"); request.setAttribute("htmlTable", htmlTable.toString()); request.getRequestDispatcher("/listar.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); } - Assistant
Tu código parece estar mayormente correcto, pero hay un detalle en el script de
jquery.dataTables.min.jsque podría estar causando el problema de que no se muestra la lista en tulistar.jsp.El problema podría estar en esta línea del script de tu JSP:
javascriptnew DataTable('#listarPedidos');Deberías asegurarte que la inicialización de DataTables se haga correctamente. La forma adecuada con JQuery suele ser: