帮助在春季捕获会话超时

blo*_*824 2 java session spring timeout

我有一个简单的Spring 3 MVC应用程序.我正在使用sessionAttribute,一切正常,除非我让页面停留30分钟或更长时间.然后我得到一个

org.springframework.web.HttpSessionRequiredException

告诉我在会话中找不到我的对象.

我想我需要在会话超时发生时以某种方式重定向回同一页面.我不确定如何正确使用弹簧.

无需登录,我已经在检查对象是否为空.

任何建议,将不胜感激.

谢谢

luk*_*ymo 7

您可以将错误页面绑定添加到HttpSessionRequiredException,它将重定向到应用程序中的第一页

例:

web.xml中

<web-app>
    <error-page>
        <exception-type>org.springframework.web.HttpSessionRequiredException</exception-type>
        <location>/index.jsp</location>
    </error-page>
</web-app>
Run Code Online (Sandbox Code Playgroud)