java 在 struts2 中处理会话超时的最佳方法是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3788336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:22:24  来源:igfitidea点击:

What is the best approach to handle session timeouts in struts2

javaweb-applicationsstruts2session-timeout

提问by codea

I have a struts2 app and I need to handle the session-timeout in the logged section.

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

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.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>

Is there a better approach ?

有没有更好的方法?

Thanks!

谢谢!

回答by Jinesh Parekh

You are on the right track.

你在正确的轨道上。

回答by joeljil

try this: http://nickcoblentz.blogspot.com/2008/11/page-level-access-controls-in-struts-2.htmland in web.xml:

试试这个: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>    

this is for 30 minutes

这是 30 分钟