我到处都找,但还没有找到一个简单的解决方案。SpringMVC会话超时 - 重定向到一个特殊的JSP
我们有一个特殊的JSP,timeout.jsp,每当SpringMVC模块截获无效会话操作时都需要显示。超时已在web.xml中配置并正常工作。
以前在Struts中,这是向前定义和拦截dispatchMethod的问题,
<forward name="sessionTimeout" path="/WEB-INF/timeout.jsp" redirect="false" />
@Override
protected ActionForward dispatchMethod(final ActionMapping mapping, final ActionForm form,
final HttpServletRequest request, final HttpServletResponse response, final String name)
throws Exception {
//...
if (!isSessionValid())
return mapping.findForward("sessionTimeout");
}
但你会如何实现用SpringMVC中模块一个包罗万象的解决方案?
我所有的网址,用SpringMVC来到这个servlet映射,* .mvc:
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.mvc</url-pattern>
</servlet-mapping>
凡是发送URL这种模式应该是交叉检查会话有效性和若无效,重定向到超时。 jsp。
注意 这里给出的解决方案(https://stackoverflow.com/a/5642344/1005607)没有不工作:
<web-app>
<error-page>
<exception-type>org.springframework.web.HttpSessionRequiredException</exception-type>
<location>/index.jsp</location>
</error-page>
</web-app>
只要我试图访问有一个在我用SpringMVC表单代码NullPointerException异常甚至任何形式收到SessionRequiredException之前,会议。我需要全局防范这些NullPointerException。
嗨基因,你可以使用拦截此功能的SO线程,让你开始http://stackoverflow.com/questions/8295977/interceptors-in-spring-mvc –