Struts2 session expired

+1 vote
asked Jul 20, 2012 by ppb

I am using struts2jquery grid plugin for my app. I am using interceptor for session timeout and I am configuring my session timeout in web.xml, But the problem is after session timeout it is not going to required page say login.jsp , my struts.xml is as follows..

....

<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>
...

I able to go in interceptor class while debug but it not redirect me to the login page. Please anybody tell me what is the problem in my code?

My interceptor method is..

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

1 Answer

0 votes
answered Jul 20, 2012 by uchenna-nwanyanwu

Check if you can modify or adapt this post. I think it is similar to what you are trying to do.

Suggestion You can alternatively use this in your jsp if it suits your needs. It is a meta tag, add it in the head tag of your jsp. When the session times out, it will automatically forward to the sessionexpired.jsp jsp. <meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval};url=sessionexpired.jsp" />

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...