我在this issue中运行,如何在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));

08-06 07:59