简体   繁体   English

JSP中的IE后退按钮问题

[英]IE Back Button issue in jsp

i am having 2 jsp pages test1.jsp and test2.jsp on test1.jsp i am posting some data and it will redirected to test2.jsp . 我在test1.jsp上有2个jsp页面test1.jsp和test2.jsp,我正在发布一些数据,它将重定向到test2.jsp。 but from test2.jsp if i clicked ie browser back button then it is showing Webpage has Expired page so how shall i proceed to show test1.jsp on back button click? 但是如果我单击test2.jsp,即单击浏览器后退按钮,那么它显示的网页已过期,因此如何继续单击后退按钮来显示test1.jsp? i am getting this issue in IE browser. 我在IE浏览器中遇到此问题。

Thus, you're actually not redirecting the request, but just POST ing (and forwarding) the request. 因此,您实际上不是在重定向请求,而只是POST (和转发)请求。 You will namely get this error page whenever you tries to get a non-cached POST request from the browser history. 每当尝试从浏览器历史记录中获取未缓存的POST请求时,即会获得此错误页面。

You need to actually redirect the request after POST . 实际上需要 POST 之后 重定向请求。 This is called the POST-Redirect-GET pattern . 这称为POST-Redirect-GET模式 Assuming that your webapplication is well designed and that you're using a Servlet to control, preprocess and postprocess requests, then all you need to do is to invoke HttpServletResponse#sendRedirect() instead of RequestDispatcher#forward() : 假设您的Web应用程序设计合理,并且您正在使用Servlet来控制,预处理和后处理请求,那么您所需要做的就是调用HttpServletResponse#sendRedirect()而不是RequestDispatcher#forward()

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Postprocess request parameters here.

    // Finally redirect POST request to a brand new GET request.
    response.sendRedirect("result.jsp");
}

This way the POST request won't be taken in the browser history. 这样, POST请求将不会出现在浏览器历史记录中。 Pressing the back button will not get the POST request anymore, but the request which was invoked before it (ie the request used to open/view the page with the form). 按下后退按钮将不再获得POST请求,而是获得之前调用的请求(即用于打开/查看带有表单的页面的请求)。

The only caveat is that the initial request, including all of its parameters and attributes will disappear as well so that you can't make use of them in the result page. 唯一需要注意的是,初始请求(包括所有参数和属性)也会消失,因此您无法在结果页面中使用它们。 If necessary, you can go around this by using the session scope or a querystring/pathinfo in the redirect URL. 如有必要,您可以通过使用会话作用域或重定向URL中的querystring / pathinfo解决此问题。

This particular "problem" is by the way not MSIE specific. 顺便说一下,这个特定的“问题”不是MSIE特有的。 Other browsers will behave the same, they would however only give a bit different error/warning message. 其他浏览器的行为相同,但是它们只会给出一些不同的错误/警告消息。 In the future, before explicitly pointing MSIE as the root cause, please test with different browsers. 将来,在明确指出MSIE是根本原因之前,请使用其他浏览器进行测试。

看一下“ 邮寄后重定向”模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM