Servlet或JSP - 如何在不丢失数据的情况下重定向发布请求 [英] Servlet or JSP - How do I redirect a post request without data loss

查看:348
本文介绍了Servlet或JSP - 如何在不丢失数据的情况下重定向发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器已移至新位置,我需要将请求重定向到新位置。如果我使用HttpServletResponse.sendRedirect(new_server_location),我将丢失原始请求附带的所有POST数据。是否可以重定向到新位置而不会丢失任何POST数据? POST数据可以包含密码等敏感信息。因此,在新服务器位置发出GET请求不是一种选择。

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.

提前感谢您的回复。

推荐答案

sendRedirect()默认情况下是HTTP 302重定向。您想要发送HTTP 307重定向。

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.

这篇关于Servlet或JSP - 如何在不丢失数据的情况下重定向发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆