HttpSession.setMaxInactiveInterval not working in Tomcat 6
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 excepti开发者_Go百科ons:
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
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.
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.
精彩评论