Java 在struts2中处理会话超时的最佳方法是什么
我有一个struts2应用程序,我需要在日志部分处理会话超时 我的想法是使用拦截器类:Java 在struts2中处理会话超时的最佳方法是什么,java,web-applications,struts2,session-timeout,Java,Web Applications,Struts2,Session Timeout,我有一个struts2应用程序,我需要在日志部分处理会话超时 我的想法是使用拦截器类: public class SessionInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { Map<String,Object> session = invocation.getInv
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();
}
}
公共类SessionInterceptor扩展了AbstractInterceptor{
@凌驾
公共字符串截获(ActionInvocation调用)引发异常{
映射会话=invocation.getInvocationContext().getSession();
if(session.isEmpty())
返回“会话”;
返回invocation.invoke();
}
}
在my struts.xml中:
<struts>
<interceptor name="session" class="org.app.struts.interceptor.SessionInterceptor" />
<interceptor name="admin" class="org.app.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>
page.jsp
error.jsp
sessionexpired.jsp
有更好的方法吗
谢谢 你走对了方向。试试这个: 在web.xml中:
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
30
这是30分钟