Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在struts2中处理会话超时的最佳方法是什么_Java_Web Applications_Struts2_Session Timeout - Fatal编程技术网

Java 在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

我有一个struts2应用程序,我需要在日志部分处理会话超时

我的想法是使用拦截器类:

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分钟