What is the best approach to handle session timeouts in struts2
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="org.app.struts.interceptor.SessionInterceptor" />
<interceptor name="admin" class="org.app.struts.interceptor.AdminInterceptor" />
<intercept开发者_StackOverflow中文版or-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!
You are on the right track.
try this: http://nickcoblentz.blogspot.com/2008/11/page-level-access-controls-in-struts-2.html and in web.xml:
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
this is for 30 minutes
精彩评论