How to get HttpSession object from SessionID?

I want to cancel user sessions based on an event. I store their sessionID, how to get their HttpSession from this ID? The HttpSessionContext class is deprecated without replacement.

+4
source share
2 answers

Servlet 2.2 specifically rejected this for security reasons, so there should not be an official way to do this. Not recommended, but you can try using Manager.findSession () if using Tomcat.

I just uninstalled HttpSession from my application. It is very difficult to synchronize sessions when many servers are running. We tried to configure it by writing our own manager, but we can not get it to work correctly. Finally, we wrote our own session with approximately 500 lines of code, and it works much better.

+3
source

Methods that already do this are deprecated. But you can implement your idea using the HttpSessionListener when a new session is created storing it in a HashMap with the session ID as the key, and the object is the actual HttpSessionObject. You can get the link.

+6
source

All Articles