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


        <interceptor name="SessionCheckInterceptor" class="" />
        <interceptor-stack name="testSessionValidationStack">
            <interceptor-ref name="SessionCheckInterceptor" />
            <interceptor-ref name="defaultStack" />
<action name="mytable" class="">
        <interceptor-ref name="testSessionValidationStack"/>    
        <result name="success" type="json"/>            
        <result name="error">messages.jsp</result>
        <result name="sessionexpired">login.jsp</result>

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();" retrived session..." + sessionMap);
    if (sessionMap == null || sessionMap.isEmpty()
            || sessionMap.get("userName") == null) {" 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