使 javax.servlet.http.HttpSession 在某些页面上不超时
我正在重构一个正在执行自己的会话超时管理的应用程序。我注意到 HttpSession 支持设置超时值。
有一个事件侦听器(我假设是 HttpSessionListener)正在重定向到“超时”页面。 “我们很抱歉您的会话已过期,这是登录页面的链接”之类的事情。
问题是,当我第一次点击应用程序并坐在登录页面上时,会话超时事件仍然会触发。所以我可以查看登录页面并重定向到超时页面。
我想要发生的是,如果我位于登录页面并且仅位于登录页面,则不会发生会话超时。我该怎么做?
我已经尝试在登录的 ActionBean 中的默认视图分辨率中调用 HttpSession.setMaxInactiveInterval(-1)
,但这不起作用。
我相信每当访问任何页面时都会创建会话,但不一定经过身份验证。
I'm refactoring an application which was doing its own session timeout management. I noted that the HttpSession supports setting a timeout value.
There is an event listener (HttpSessionListener I assume) that is redirecting to a 'timeout' page. "We're sorry your session expired, heres a link to the login page" kind of thing.
The problem is that when I first hit the app and am sitting on the login page, the session timeout event still fires. So I can be looking at the login page and get redirected to the timeout page.
What I want to happen is that if I am on the login page and only on the login page, that the session timeout does not occur. How do I do this?
I have already tried calling HttpSession.setMaxInactiveInterval(-1)
in the default view resolution in the login's ActionBean, but that did not work.
I believe the session is being created, but not necessarily authenticated, whenever any page is accessed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里进行重定向?如果它是在配置文件中某处以声明方式设置的内容,您可以将其删除并实现 HttpSessionListener 接口。
在 sessionDestroyed 方法中,您将执行以下操作:
您还可以保留用户请求的最后一个页面,并将其用作参考来确定是否重定向,但如果用户已经通过身份验证并浏览到登录页面,您该怎么办?我没有关于您的申请的很多信息。
无论如何,我认为 HttpSessionListener 是可行的方法。
Where do you have the redirecting happening? If it's something declaratively set somewhere in a configuration file you could remove it and implement the HttpSessionListener interface.
In the sessionDestroyed method u would make the following:
U could also keep the last page requested by the user and use that as a reference to determine whether to redirect or not but what do you do if a user is already authenticated and browses to the login page? I do not have a lot of information about your application.
Anyway the HttpSessionListener is the way to go I think.