Sending redirect to another servlet/JSP without loosing the request parameters.

前端 未结 2 1843
有刺的猬
有刺的猬 2020-12-05 15:50

How do i specify a redirection to another servlet, in the doPost() method of a servlet.

at the moment I\'m using

request.getRequestDispatcher(\"/WEB-         


        
相关标签:
2条回答
  • 2020-12-05 16:21

    In your doPost you can always call:

    return doGet(request, response);
    
    0 讨论(0)
  • 2020-12-05 16:25

    You need to use HttpServletResponse#sendRedirect() to send a redirect. Assuming that the servlet is mapped on an URL pattern of /products:

    response.sendRedirect("/products");
    

    This way the webbrowser will be instructed to fire a new HTTP GET request on the given URL and thus the doGet() method of the servlet instance will be called where you can in turn load the products and forward to a JSP which displays them the usual way.

    0 讨论(0)
提交回复
热议问题