我在我的应用程序中使用struts2jquery网格插件。我使用拦截器进行会话超时,并在web.xml中配置会话超时,但问题是会话超时之后它将不需要页面(例如login.jsp ),我的struts.xml如下所示。
....
<interceptors>
<interceptor name="SessionCheckInterceptor" class="com.org.SessionCheckInterceptor" />
<interceptor-stack name="testSessionValidationStack">
<interceptor-ref name="SessionCheckInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
...
<action name="mytable" class="com.org.MyTable">
<interceptor-ref name="testSessionValidationStack"/>
<result name="success" type="json"/>
<result name="error">messages.jsp</result>
<result name="sessionexpired">login.jsp</result>
</action>
...
我可以在调试时进入拦截器类,但它不会将我重定向到登录页面。请有人告诉我我的代码有什么问题吗?
我的拦截方法是..。
public String intercept(ActionInvocation actionInvocation) throws Exception {
ActionContext context = actionInvocation.getInvocationContext();
Map<String, Object> sessionMap = context.getSession();
log.info(" retrived session..." + sessionMap);
if (sessionMap == null || sessionMap.isEmpty()
|| sessionMap.get("userName") == null) {
log.info(" session expired...");
addActionError(actionInvocation,"Session has been expired,please login again.");
return "sessionexpired";
}
String actionResult = actionInvocation.invoke();
return actionResult;
}
发布于 2012-07-19 23:33:52
检查是否可以修改或修改此post。我认为这和你想做的事情很相似。
如果适合您的需要,可以在jsp中使用建议。它是一个元标记,将其添加到jsp的head
标记中。当会话超时时,它将自动转发到sessionexpired.jsp
jsp。<meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=sessionexpired.jsp" />
https://stackoverflow.com/questions/11573580
复制