我到處都找,但還沒有找到一個簡單的解決方案。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 –