繁体   English   中英

以编程方式设置Jetty会话cookie名称

[英]Set Jetty session cookie name programmatically

我正在运行这个问题 ,如何通过Jetty 8中的代码设置会话cookie名称?

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
sessionHandler = new SessionHandler();
sessionHandler.getSessionManager().setSessionCookie("JSESSIONID_"+runningPort);
context.setSessionHandler(sessionHandler);

错了,在Jetty8中, SessionManager setSessionCookie(String)被删除了。

这是答案:

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
SessionManager sm = new HashSessionManager();
((HashSessionManager)sm).setSessionCookie("JSESSIONID_"+activity.WEB_SERVER_PORT);
context.setSessionHandler(new SessionHandler(sm));

我不得不用Jetty 9.3解决这个问题,解决方案略有不同:

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

尝试使用Servlet 3.0会话配置,这是一个可以帮助您的文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM