Jetty 8 set "session-timeout" without web.xml?

2019-05-11

For Jetty version 9.4.12.v20180830 with the following ServletContextHandler setup, this is:

ServletContextHandler webappContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
... 
webappContext.getSessionHandler().setMaxInactiveInterval(timeout_in_sec);

(There is no intermediate call to getSessionManager())


Access the session handling / management on your WebAppContext and set it.

WebAppContext app = new WebAppContext(....);
... 
app.getSessionHandler().getSessionManager().setMaxInactiveInterval(timeout);

This is how Jetty itself does it.

Note: SessionManager.setMaxInactiveInterval(int) is in seconds, not milliseconds.