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