退出问题!

发布于 2024-10-31 11:33:31 字数 410 浏览 0 评论 0原文

我有大约 30 个带有登录和注销的 jsp 页面。我已将所有页面放入会话中,以便只有有效的用户才能访问。现在的问题是,每当用户注销时,会话就会失效,但如果用户按下浏览器的后退按钮,它仍然会显示受保护的页面(不应显示)。

我了解到问题出在保存缓存和历史记录的浏览器上。因此,我在安全页面上应用了 response.setheader("cache-control",.....) 等,也在 window.history.go(+1) 中应用了受保护页面的正文。

它在某种程度上工作正常,但偶尔会显示受保护的页面。而且,一旦用户登录会话开始并且当他进入网站时,后退按钮应该可以毫无麻烦地为他工作(不会提示用户重新发送表单数据)。一旦他注销,会话就应该结束,并且他应该无法再通过点击后退按钮访问页面。有什么办法可以实现这一点吗?

I have some 30 jsp pages with login and logout. I have put all the pages in the Session, so that only valid user can have access. Now the problem is, whenever user hits the logout the session gets invalidated but if the user presses the back button of the browser still it displays the secured pages (which shouldn't get displayed).

I got to know that the problem was with the browser which holds the cache and history. So I applied response.setheader("cache-control",.....) etc. on secured pages and also window.history.go(+1) in the body of secured pages.

It works fine to some extent but once in a while it displays the secured pages. And also once the user logs in session starts and when he will be inside the website, back button should work for him without any hassle (without prompting the user to resend the form data). Once he logs out the session should end and he should not be able to access the pages anymore by hitting back button. Is there any way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2024-11-07 11:33:31

1 为了检查用户是否经过身份验证,不要在 jsp 上使用代码,我们有 Filter 只使用它。

2 设置您的过滤器< /a> 执行以下操作来解决缓存问题

HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);

3 删除 javascript

1 For checking if the user is authenticated don't use code on jsp , We have Filter for that only make use of it.

2 Make your Filter to do following to resolve caching issue

HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);

3 Remove javascript

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文