Problem with SERVLET and JSP

0

I have a list of orders, when I click on one I see the detail of that order and I have a button to mark it as DELIVERED. I pass the id of the order from a jsp to a servlet and there I do the update (until here it works well), but after the update I want it to take me to the jsp with the list of orders, but this does not happen.

Details Order.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <c:set var="pedido" value="${pedido}"/>
        <c:if test="${pedido != null}">
            <div>
                <p><label>Código: </label> ${pedido.id}</p>
                <p><label>Descripción: </label> ${pedido.descripcion}</p>
                <p><label>Dirección: </label> ${pedido.direccion}</p>
                <p><label>Precio: </label> U$ ${pedido.precio}</p>
                <p><label>Fecha: </label> ${pedido.fechaHora}</p>
                <a class="btn btn-info" role="button" href="VerRutaServlet?id=${pedido.id}">Ver ruta de entrega</a>
                <a class="btn btn-info" role="button" href="PedidoEntregadoServlet?id=${pedido.id}">ENTREGADO</a>
            </div>
        </c:if>
    </body>
</html>

OrderServlet.javaService

@WebServlet(name = "PedidoEntregadoServlet", urlPatterns = {"/PedidoEntregadoServlet"})
public class PedidoEntregadoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {


        String id = request.getParameter("id");
        Consulta cons;
        boolean funciono = false;
        try{
            cons = new Consulta("*", "pedidos");
            if (cons.actualizarPorId(Integer.parseInt(id), "estado = 'ENTREGADO'")){
                funciono = true;
            }
            if (funciono)
                request.getRequestDispatcher("/repartidores/Pedidos.jsp").forward(request, response);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(ConsultaPedidosServlet.class.getName()).log(Level.SEVERE, null, ex.getMessage());
        } 
    }
}

In the url I have: link

but I want it to be: link , this is the one that shows all orders and works correctly.

    
asked by Juan Manuel 09.11.2016 в 15:23
source

1 answer

1

In your code change request.getRequestDispatcher("/repartidores/Pedidos.jsp").forward(request, response); for this function response.sendRedirect('consultaPedidosServlet') thus rediriges the request to the requested JSP.

    
answered by 09.11.2016 / 15:39
source