1

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;
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
ppb
  • 2,299
  • 4
  • 43
  • 75
  • can you show you interceptor method code – Umesh Awasthi Jul 20 '12 at 06:08
  • I am editing my question with interceptor method code. – ppb Jul 20 '12 at 06:20
  • Why do you not use a security framework like Spring Security? Handles all these things and much more for you. – Hugo Jul 20 '12 at 06:26
  • on session timeout to which page you are getting redirected? – Umesh Awasthi Jul 20 '12 at 06:32
  • @Hugo: If this is only requirement i will not favour adding one more API, but if requirement is much more i am fully agree with you – Umesh Awasthi Jul 20 '12 at 06:33
  • @Umesh: On session timeout nothing is happen, after session timeout shows same page where I was. – ppb Jul 20 '12 at 06:52
  • @Hugo: can you please provide me the link for tutorial that how can I use Security Framework like spring in struts2. – ppb Jul 20 '12 at 06:52
  • A simple [tutorial](http://techblog.zabuchy.net/2011/spring-security-3-basic-integration-and-access-decision-manager/) for starting up. You can use a release version, instead of the SNAPSHOT version in the tutorial. Then consult the [Spring Security documentation](http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity.html). It might be some effort to figure things out, but when you have a simple login page and a bunch of urls you want to secure, it is not that hard. – Hugo Jul 20 '12 at 08:58
  • I have a doubt, session invalidation shouldn't perform in interceptors but we can do check like valid session or not. Cause interceptors triggered before and after action execution. In such a case if the session has reached inactive interval time It should be automatically go to login page.(using JS by explicitly calling logout action which is having responsibility of invalidating session. – MohanaRao SV Jul 21 '12 at 05:00

1 Answers1

0

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" />

Community
  • 1
  • 1
Uchenna Nwanyanwu
  • 3,174
  • 3
  • 35
  • 59