帮助捕获春季的会话超时
我有一个简单的 Spring 3 MVC 应用程序。我正在使用 sessionAttribute,一切正常,除非我让页面停留 30 分钟或更长时间。然后我得到一个
org.springframework.web.HttpSessionRequiredException
告诉我在会话中找不到我的对象。
我想当会话超时发生时我需要以某种方式重定向回同一页面。我不知道如何用 spring 正确地做到这一点。
不需要登录,我已经在检查对象是否为空。
任何建议将不胜感激。
谢谢
I have a simple Spring 3 MVC application. I am using a sessionAttribute and everything works fine except when I let the page sit for 30 minutes or longer. I then get a
org.springframework.web.HttpSessionRequiredException
telling me my object is not found in session.
I am thinking I need to somehow redirect back to the same page when a session timeout occurs. I am not sure how to do this correctly with spring.
There is no login required and I am already checking if the object is null.
Any suggestions would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将错误页面绑定添加到 HttpSessionRequiredException ,这将重定向到应用程序中的首页
example:
web.xml
You can add error-page binding to HttpSessionRequiredException which will redirect to first page in your application
example:
web.xml
您无法直接重定向“返回同一页面”。你的session消失了,也就是说你在客户端的cookie不再对应servlet容器中的任何session,因为session对象被从内存中删除了。彻底、不可逆转。
您可以增加会话超时。这是应用程序配置,而不是 Spring:
web.xml:
将为您提供两个小时的空闲会话。
请注意,会议不是免费的。它们消耗资源(序列化时的内存和磁盘)。如果同一用户可以多次重新登录,他们将有多个空闲会话,并可能导致 DoS。
PS 如果您同意消失的会话,并且只想立即建立另一个会话,那么您始终可以在过滤器中执行此操作,无论是否为 Spring。 Spring 可能有自己的监听器。您必须在全新的会话中放置一些内容才能使您的请求发挥作用。
There is no way you can just redirect "back to the same page". You session is gone, that is the cookie you have on the client is no longer correspond to any session in the servlet container, because session object was deleted from memory. Totally, irreversibly.
You may increase session timeout. This is application configuration, not Spring:
web.xml:
will give you two hours of idle session.
Note that sessions are not free. They consume resources (memory and disk, when serialized). If the same user can re-login multiple time, they'll have multiple idle sessions, and potentially could cause you DoS.
P.S. If you OK with gone session, and just want to establish another one right away, you can always do it in a filter, Spring or not. Spring may have their own listeners. You'd have to place something into that brand new session to make your request work.