title: What is the best approach to handle session timeouts in struts2
body: <p>I have a struts2 app and I need to handle the session-timeout in the logged section.</p>
  
  <p>What I have in mind is to use an Interceptor class :</p>
  
  <pre><code>public class SessionInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        Map&lt;String,Object&gt; session = invocation.getInvocationContext().getSession();
        if(session.isEmpty())
            return "session";
        return invocation.invoke();
    }
  }
  </code></pre>
  
  <p>In my struts.xml :</p>
  
  <pre><code>&lt;struts&gt;
    &lt;interceptor name="session" class="org.app.struts.interceptor.SessionInterceptor" /&gt;  
    &lt;interceptor name="admin" class="org.app.struts.interceptor.AdminInterceptor" /&gt;
  
    &lt;interceptor-stack name="adminStack"&gt;
      &lt;interceptor-ref name="defaultStack"/&gt;
      &lt;interceptor-ref name="session"/&gt;
      &lt;interceptor-ref name="admin"/&gt;
    &lt;/interceptor-stack&gt;
  
    &lt;action name="doaction" class="org.app.class" method="doAction"&gt;
      &lt;interceptor-ref name="adminStack" /&gt;
      &lt;result name="success"&gt;page.jsp&lt;/result&gt;
      &lt;result name="error"&gt;error.jsp&lt;/result&gt;
      &lt;result name="session"&gt;sessionexpired.jsp&lt;/result&gt;
    &lt;/action&gt;
  &lt;/struts&gt;
  </code></pre>
  
  <p>Is there a better approach ?</p>
  
  <p>Thanks!</p>