如何从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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已经这样做的方法已被弃用。
但是您可以使用 HttpSessionListener 实现您的想法,当创建新会话时,将其存储在 HashMap 中,以会话 id 作为键,对象是实际的 HttpSessionObject。 你可以通过这个得到参考。
The methods that are already doing this are deprecated.
But you can implement the your idea useing HttpSessionListener, when a new session is created store it in a HashMap with session id as a key and object is actual HttpSessionObject. You can get the reference by this.
出于安全原因,Servlet 2.2 明确弃用了这一点,因此不应该有任何官方方法来执行此操作。 不推荐,但如果您使用 Tomcat,可以尝试使用 Manager.findSession()。
我刚刚从我的应用程序中删除了 HttpSession。 当许多服务器运行时,保持会话同步确实很困难。 我们试图通过编写自己的管理器来调整它,但永远无法让它正常工作。 最后,我们用大约 500 行代码编写了自己的会话实现,效果好多了。
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.
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.