如何使用tomcat的catlina api來訪問會話管理。我有一個要求使我的代碼中的其他用戶的會話無效。如何使用tomcat的catlina api來訪問會話管理
3
A
回答
2
我個人更喜歡不要綁定到Tomcat包,並儘可能多地使用javax.servlet
API,原因很明顯。你的任務可以通過創建一個會話監聽器,並保持所有會話的WeakHashMap
來實現,像這樣
<!-- your webapp's web.xml -->
<listener>
<listener-class>path.to.SessionListener</listener-class>
</listener>
class SessionListener implements HttpSessionListener {
private static final Map<String, HttpSession> sessions = Collections.synchronizedMap(new WeakHashMap<String, HttpSession>());
public void sessionCreated(HttpSessionEvent event) {
sessions.put(event.getSession().getId(), event.getSession());
}
public void sessionDestroyed(HttpSessionEvent event) {
sessions.remove(event.getSession().getId());
}
}
其餘如添加另一種方法,通過所有會話迭代和無效一樣簡單。
0
使用session.invalidate方法爲特定用戶喜歡。
如果您在session.set屬性中設置用戶,則從訪問器方法獲取該particualr方法。
使用pojo bean來處理它。
在使會話無效之前,請檢查它是否爲真或有效。
相關問題
- 1. Tomcat如何管理會話?
- 2. Tomcat:如何從servlet訪問(會話)管理器
- 3. Tomcat中的會話管理
- 4. 管理會話phonegap restful API?
- 5. 帶Memcached會話管理器的Tomcat 7
- 6. 如何創建類來管理會話?
- 7. 用戶可以訪問管理頁面使用會話在php
- 8. 如何使用ajax管理會話
- 9. 會話管理問題
- 10. TOMCAT - 無法訪問管理器應用
- 11. 使用Anypoint訪問管理 - Mulesoft API
- 12. 如何訪問compojure-api處理程序中的會話?
- 13. 會話管理問題
- 14. 需要自定義會話管理器幫助 - 如何訪問會話信息?
- 15. 如何使用Firebase身份驗證來管理對現有API(nodejs)的訪問
- 16. Tomcat會話處理
- 17. Http會話管理/可選會話管理(Java)
- 18. Tomcat,會話管理員。什麼意思與負TTL會話?
- 19. 使用Tomcat和cookies進行會話管理
- 20. 訪問來自不同主機的tomcat管理器
- 21. 會話管理
- 22. 如何在tomcat負載平衡中管理會話?
- 23. Memcached和Tomcat 8會話管理器問題
- 24. 訪問Tomcat管理器拋出404
- 25. 禁止遠程訪問Tomcat管理器?
- 26. 我無法訪問Apache Tomcat管理器?
- 27. Web API中的NHibernate會話管理
- 28. Tomcat如何在內部處理會話?
- 29. 在代理之外訪問Apache Tomcat應用程序的會話問題
- 30. PHP會話。管理員如何銷燬用戶的會話
不能讓你可以簡單介紹一下...... – TaherT