如何从SessionID获取HttpSession对象? [英] How to obtain an HttpSession Object from SessionID?

查看:1020
本文介绍了如何从SessionID获取HttpSession对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望根据某些事件使用户会话无效。我存储了他们的sessionID,如何从这个ID获取他们的HttpSession?
不推荐使用HttpSessionContext类,没有替换。

I want to invalidate sessions of users based on some Event. I store their sessionID, how to get their HttpSession from this ID? The HttpSessionContext class is deprecated with no replacement.

推荐答案

出于安全原因,Servlet 2.2特别弃用了这个,所以不应该'这是任何官方的方式来做到这一点。不建议但是如果你使用Tomcat,你可以尝试使用Manager.findSession()。

Servlet 2.2 specifically deprecated this for security reasons so there shouldn't be any official way to do this. Not recommended but you can can try to use Manager.findSession() if you use Tomcat.

我刚从我的应用程序中删除了HttpSession。当许多服务器运行时,很难保持会话同步。我们试图通过编写我们自己的经理来调整它,但永远不能让它正常工作。最后,我们用大约500行代码编写了自己的会话实现,它的工作效果要好得多。

I just removed HttpSession from my application. It's really hard to keep sessions in sync when many servers are running. We tried to tweak it by writing our own manager but can never get it work right. Finally, we wrote our own session implementation with about 500-lines of code and it works much better.

这篇关于如何从SessionID获取HttpSession对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆