什么是处理 Struts2 会话超时的最佳方法?

3

我有一个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();
  }
}

在我的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>

有更好的方法吗?
谢谢!
2个回答

1

你走在正确的道路上。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接