【问题标题】:What is the best approach to handle session timeouts in struts2在struts2中处理会话超时的最佳方法是什么
【发布时间】:2010-09-24 15:00:48
【问题描述】:

我有一个 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>

有没有更好的方法?

谢谢!

【问题讨论】:

    标签: java web-applications struts2 session-timeout


    【解决方案1】:

    你在正确的轨道上。

    【讨论】:

      【解决方案2】:

      试试这个:http://nickcoblentz.blogspot.com/2008/11/page-level-access-controls-in-struts-2.html 在 web.xml 中:

      <session-config>  
              <session-timeout>  
                  30  
              </session-timeout>  
          </session-config>    
      

      这是 30 分钟

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-19
        • 2012-03-30
        • 1970-01-01
        • 1970-01-01
        • 2011-12-09
        • 2010-09-11
        • 2013-01-21
        • 1970-01-01
        相关资源
        最近更新 更多