I'm running in this issue, how can I set session cookie name by code in Jetty 8?
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
sessionHandler = new SessionHandler();
sessionHandler.getSessionManager().setSessionCookie("JSESSIONID_"+runningPort);
context.setSessionHandler(sessionHandler);
Is wrong, in Jetty8 SessionManager
setSessionCookie(String)
was removed.
Here is the answer:
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
SessionManager sm = new HashSessionManager();
((HashSessionManager)sm).setSessionCookie("JSESSIONID_"+activity.WEB_SERVER_PORT);
context.setSessionHandler(new SessionHandler(sm));
I had to solve this problem with Jetty 9.3 and the solution is slightly different:
SessionManager sessionManager = new HashSessionManager();
sessionManager.setMaxInactiveInterval(60 * 15); //session time out of 15 minutes
HashSessionIdManager idManager = new HashSessionIdManager();
sessionManager.getSessionCookieConfig().setName("JSESSIONID_" + Integer.toString(m_serverSettings.getM_webServerPort()));
sessionManager.setSessionIdManager(idManager);
SessionHandler sessionHandler = new SessionHandler(sessionManager);
Try to use Servlet 3.0 Session Configuration , here is a doc that could help you.