簡體   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