• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting HTTP Session by using Session ID

 
Pk Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I using HttpSessoin to create session and I need to get already created session (HttpSession) using session ID (JSessionID). Please let me know how can I do that.

Thanks
PRADEEP
 
Hany Shafik
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.
Can I ask you why you want to this, there may be a better solution for it?
However you can implement a session listener and in the sessionCreated method add an entry in a singleton map that holds all your session as values and the session Ids as keys, the map should be synchronized.
Please be careful that this solution won't work if you have a clustered web application.
 
Pk Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thans Hany....

Why I need this because I will be getting session ID (Jsessionid) in GET request and need to retrieve the same session again. Please let me know the better way to do so.

Thanks
Pradeep
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need the ID? You can get the current session directly.
 
Devaka Cooray
Marshal
Posts: 5158
480
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pk Singh wrote:Why I need this because I will be getting session ID (Jsessionid) in GET request

Did you mean the jsessionid which is appended to the URL by the container for url rewriting?
like in http://youapp.com;jsessionid=DA32242SSGE2 ?

In that case, you don't need to track the session yourself. It's up to the container - container reads the jsessionid and retrieves the session. The getSession() method HttpServletRequest simply returns the session - you don't need to do anything other than that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!