Java Servlet向其自身转发的网页在浏览器后退/前进按钮上的行为不正确 [英] webpage forward to itself by Java Servlet doesn't act correct on browser back/forward button

查看:59
本文介绍了Java Servlet向其自身转发的网页在浏览器后退/前进按钮上的行为不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试设计一个讨论论坛,但似乎有一些问题.在我的示例中,我的论坛的结构是topicPage.jsp包含一堆主题,replyPage.jsp包含一堆回复和一个textArea允许人们回复该主题.现在我遇到了一个问题,如果用户发布了答复,并且他想返回到topicPage.jsp,则单击浏览器的后退"按钮,浏览器就没有转到topicPage.jsp,而是这样做了.仍停留在replyPage.jsp的状态,即用户提交其答复之前的状态.

I try to design a discussion forum but it seems to have a little problem. For my example, structure of my forum is topicsPage.jsp contains a bunch of topics, and replyPage.jsp contains a bunch of replies and a textArea allows people to reply to that topic. and now I got a problem, if an user posted a reply, and he want to go back to the topicPage.jsp, he clicked browser's back button, the browser didn't go to topicsPage.jsp, instead of doing that, the browser still stay at replyPage.jsp with the state which before user submit his reply.

我相信这不是唯一会导致此问题的情况,任何需要servlet转发到原始网页的情况都会出现此问题.有什么办法可以解决这个问题?

I believe this is not the only situation will cause this problem, any situation which needs servlet to forward to the original webpage will having this problem. is there any ways to solve this problem?

推荐答案

作为一般规则,在提交(post)之后,您应该始终进行重定向而不是转发.它避免了浏览器的后退按钮带来的许多问题.这称为发布-重定向-模式

As a general rule, you should always do a redirect and not a forward after a submit (post). It avoids a lot of problems with the back button of the browser. That is called the post - redirect - pattern

这篇关于Java Servlet向其自身转发的网页在浏览器后退/前进按钮上的行为不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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