tengo este metodo para listar - @WebServlet("/pedidos") public class PedidosServlet…
- User
tengo este metodo para listar - @WebServlet("/pedidos") public class PedidosServlet extends HttpServlet{
private Pedidos pedidoWS = new Pedidos(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws 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(); } }suguiendo las buenas practicas de progrmacion es necesario ocultar los valores que se van a listar o puedo hacer el listado directamente en el jsp - <%= request.getAttribute("htmlTable") %>
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.