代码之家  ›  专栏  ›  技术社区  ›  Drew Wills

HttpSession.setMaxInactiveInterval在Tomcat 6中不工作

  •  1
  • Drew Wills  · 技术社区  · 16 年前

    我正在尝试使用HttpSession.setMaxInactiveInterval调整会话超时,但它不起作用。

    下面是我的代码(Groovy),它执行时没有异常:

    def paramValue = WebAttributes.REQUEST.getParameter('maxInactiveSeconds');
    println 'paramValue=' + paramValue;
    if (paramValue != null) {
      def seconds = Integer.parseInt(paramValue);
      WebAttributes.REQUEST.getSession().setMaxInactiveInterval(seconds);
    }
    

    一些细节:

    谢谢

    haruspex

    2 回复  |  直到 16 年前
        1
  •  3
  •   BalusC    16 年前

    你是怎么测试的?每一个新的请求都会再次推迟超时,你知道吗?因此,在预期超时之前对请求进行F5处理是没有帮助的。webcontainer也不会立即销毁会话,因此您不会立即看到任何结果 HttpSessionListener . 它将以一定的间隔收获它们,可能是每分钟一次,也可能是每15分钟一次。然而,如果有新的请求进来,它将立即收获它 超时。

    应该 “被共享”短语,验证这一点的最佳方法当然是通过以编程方式(例如显示)检查会话ID ${pageContext.session.id} jsessionid 网络浏览器中的cookie。

    HttpSessionListener . 以下是一个基本示例:

    public class MyHttpSessionListener implements HttpSessionListener {
        public void sessionCreated(HttpSessionEvent event) {
            System.out.printf("%s session %s created %n", new Date(), event.getSession().getId());
        }
        public void sessionDestroyed(HttpSessionEvent event) {
            System.out.printf("%s session %s destroyed %n", new Date(), event.getSession().getId());
        }
    }
    

    希望这有帮助。

        2
  •  1
  •   Drew Wills    16 年前

    推荐文章