如何处理点击“返回”的用户退出后按钮

发布于 2024-12-22 05:08:31 字数 528 浏览 0 评论 0原文

我显示一条消息:

“您尚未登录”

对于点击我页面上“提交”按钮的访客, 。当然,对于登录用户,我想显示该消息。我用这种方式编码:

<c:if test="${someCondition}">
addMsgToButtonEvent();
</c:if>

它(几乎)完美地工作。但是,现在当用户登录并:

  1. 单击注销(位于我的标题中并重定向到另一个页面上)
  2. 单击浏览器上的“后退”按钮

该消息不会出现,因为我的页面未再次呈现,未调用 addMsgToButtonEvent。我知道我可以通过清除历史记录来阻止“后退”按钮 - 但这会改变业务需求太多。这是解决这个问题的一些软而有效的解决方法吗?


编辑:

我认为解决此类问题的最佳方法是注销后使会话无效。我就是这样做的。

I show a message:

"You are not logged in"

for guests who click a button "submit" on my page. Surely, for logged in users I want to not show the message. I coded this in this way:

<c:if test="${someCondition}">
addMsgToButtonEvent();
</c:if>

It works (almost) perfectly. But, now when user is logged in and:

  1. click sign out (which is in my header and redirects on another page)
  2. click "Back" button on the browser

The message doesn't appear because my page is not rendered again, addMsgToButtonEvent is not called. I know that I can block "back" button by clearing a history - but this would change too much in business requirements. Is this some soft and effective workaround on this problem?


Edited:

I think the best approach for such problem is invalidating session after sign out. I did it in this way.

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

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

发布评论

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

评论(2

狼性发作 2024-12-29 05:08:31

我在 ASP.Net 站点和登录控件方面也遇到过类似的问题。

您可以向 HTML 添加一个元标记,告诉浏览器不要缓存它 - 因此后退按钮将导致页面从服务器正确重新加载:

<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="EXPIRES" content="0">

希望可能有所帮助:)

I've had similar problems with ASP.Net sites and login controls.

You could add a meta tag to the HTML to tell the browser not to cache it - hence the back button will cause the page to be reloaded from the server correctly:

<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="EXPIRES" content="0">

Hope that might help :)

烟沫凡尘 2024-12-29 05:08:31

如果缓存有问题,请将以下行添加到 JSP 顶部

<%
response.setHeader("Cache-Control","no-cache no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

如果这不能解决问题...您可能需要查看如何处理显示代码和会话失效。

最好的方法是:

创建会话时分配一个命名属性
为了打印语句检查指定属性是否存在
如果找到命名属性...打印消息,否则不执行此操作
注销时...执行 session.invalid()

让我知道什么有效...我们可以更深入地研究这个

If caching is problem add the following lines to the top of your JSP

<%
response.setHeader("Cache-Control","no-cache no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

If that does not solve the problem ... you may want to look at how you are handling display code and session invalidation.

Best approach is:

When you create a session assign an named attribute
In order to print the statement check the existence of the named attribute
If named attribute is found ... print the message else do not do it
On logout ... do session.invalid()

Let me know what worked ... and we can dig deeper into this

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