1

我正在为我的应用程序使用 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;
}
4

1 回答 1

0

检查您是否可以修改或改编这篇文章。我认为这与您正在尝试做的事情相似。

建议 如果它适合您的需要,您也可以在您的 jsp 中使用它。它是一个元标记,将它添加head到你的 jsp 的标记中。当会话超时时,会自动转发到sessionexpired.jspjsp。 <meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=sessionexpired.jsp" />

于 2012-07-20T07:33:52.417 回答