Servlet or JSP - How do I redirect a post request

2020-05-07 19:10发布

问题:

My server moved to a new location and I need to redirect requests to the new location. If I use HttpServletResponse.sendRedirect(new_server_location), I am losing all the POST data coming along with the original request. Is it possible to redirect to the new location without losing any of the POST data? The POST data can contain sensitive information like passwords. So making a GET request on the new server location is NOT an option.

Thanks in advance for the responses.

回答1:

The sendRedirect() is by default a HTTP 302 redirect. You want to send a HTTP 307 redirect instead.

response.setStatus(307);
response.setHeader("Location", new_server_location);

This only issues a default browser warning on most browsers.