Gaurav
Gaurav

Reputation: 1554

Struts 2 after interceptor no data error

I have created a global interceptor which will check for Session timeout.

<interceptors>
                <interceptor class="com.action.SessionChecker" name="sessCheck"> </interceptor>
                </interceptors>

            <default-interceptor-ref name="sessCheck"></default-interceptor-ref>

`

Now it in SessionChecker I check for session timeout

@Override
    public String intercept(ActionInvocation arg0) throws Exception {

        String result;
        Map<String,Object> session = arg0.getInvocationContext().getSession();


          if(session.isEmpty()){

                  result="session_Timeout";

              }
          else
              result=arg0.invoke();

        return result;
    }

Before every request Interceptor is getting called but, then it does not go to action class of that request and though I get corresponding page to the request there is no data.

Upvotes: 0

Views: 508

Answers (1)

Steven Benitez
Steven Benitez

Reputation: 11055

The following line in your configuration is configuring your session timeout interceptor as the only interceptor in the stack, which is certainly not what you want.

<default-interceptor-ref name="sessCheck"></default-interceptor-ref>

Instead, you need to define a stack that contains all of the interceptors you want to use and define that as your default.

Also, the interceptor you have built is not actually detecting that a session has timed out, but rather just that a session is empty. I'm not sure what is populating your session, but if this interceptor is invoked prior to a new session being properly populated, it will be erroneously identified as timed out.

Upvotes: 2

Related Questions