您的位置:首页 > 产品设计 > UI/UE

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

2015-09-22 11:43 711 查看
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-INF/products.jsp").forward(request, response);


which is wrong since, my parameters in the doGet() method of
products
are not being called and initialized.

So I’m left with an empty products page after logging in :/

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  servlet redirect