HttpSession.setMaxInactiveInterval not working in Tomcat 6

亡梦爱人 提交于 2019-12-24 15:27:09

问题


I'm trying to adjust the session timeout using HttpSession.setMaxInactiveInterval and it's not working.

Here is my code (Groovy), which is executing without exceptions:

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

Some details:

  • Tomcat 6.0.16
  • This is happening in a webapp separate from the 'normal' one (i.e. with visual content), but I have defined emptySessionPath="true" so the session *should* be shared across webapps

thanks,

haruspex


回答1:


How did you test it? Every new request would postpone the timeout again, do you know? So F5'ing the request until the expected timeout ain't going to help. The webcontainer will also not immediately destroy the session, so you won't see immediate result from any HttpSessionListener. It will reap them at certain intervals, which may be each minute, but can also be each 15 minutes. It will however reap it immediately if a new request came in after the timeout.

With regard to your "the session should be shared" phrase, best way to verify this is of course by checking the session ID, either programmatically (e.g. displaying ${pageContext.session.id}) or by just determining the value of the jsessionid cookie in your webbrowser.

To monitor the actual session creation and destroy, implement a dummy HttpSessionListener. Here's a basic example:

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());
    }
}

Hope this helps.




回答2:


Turns out there was another technology setting the maxInactiveInterval back to 30 min, overriding my attempts to change it.

Tomcat, Java, etc. were all working as expected.



来源:https://stackoverflow.com/questions/1848327/httpsession-setmaxinactiveinterval-not-working-in-tomcat-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!