Search code examples
jettyhttpsession

Will AJAX (XmlHttpRequests) prevent my Jetty managed HttpSession from expiring?


I am using an embedded Jetty implementation as my servlet container. Here is a small config snippet:

WebAppContext context = new WebAppContext(warUrlString, "/");

SessionHandler sessionHandler = new SessionHandler();
SessionManager sessionManager = new HashSessionManager();

// in seconds, low for testing
sessionManager.setMaxInactiveInterval(20);

context.setSessionHandler(sessionHandler);

There are a few items on various pages that will update periodically through AJAX. Will these requests prevent a HttpSession from invalidating?


Solution

  • The answer is no. Although I was doing a

    server.setHandler(context);
    server.start();
    

    I had to do a (below) after the start. I am assuming that if no web.xml is specified (which I wasn't) then the jetty defaults were taking place. Therefore I had to specify the timeout after the server was inited.

    context.getSessionHandler().getSessionManager().setMaxInactiveInterval(
                maxtimeout);