2012-07-20 136 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" />