2012-07-20 134 views
1

我为我的应用使用了struts2jquery网格插件。我正在使用拦截器会话超时,我正在配置我的会话超时在web.xml中,但问题是会话超时后,它不会要求页面说login.jsp,我的struts.xml如下。Struts2会话过期

.... 

<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; 
} 
+0

你可以告诉你拦截器的方法代码 – 2012-07-20 06:08:07

+0

我正在用拦截器方法代码编辑我的问题。 – ppb 2012-07-20 06:20:55

+0

为什么你不使用像Spring Security这样的安全框架?处理所有这些事情,为您处理更多。 – Hugo 2012-07-20 06:26:54

回答

0

检查是否可以修改或调整本post。我认为它与你正在尝试做的事情类似。

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