Set Jetty session cookie name programmatically

馋奶兔 提交于 2019-12-08 07:55:27

问题


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.


回答1:


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



回答2:


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



回答3:


Try to use Servlet 3.0 Session Configuration , here is a doc that could help you.



来源:https://stackoverflow.com/questions/24017645/set-jetty-session-cookie-name-programmatically

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