aspose file tools*
The moose likes Servlets and the fly likes How to use jsessionid while making HTTP calls?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to use jsessionid while making HTTP calls?? " Watch "How to use jsessionid while making HTTP calls?? " New topic
Author

How to use jsessionid while making HTTP calls??

Shridhar. Blr.
Ranch Hand

Joined: Nov 23, 2000
Posts: 45
Hi All,

How can i use an existing jsessionid, when i make a http call..
When a first call is made to the application, we get a jsessionid, i want to use the same jsessionid, when we make next calls and how do i use it on the server side to identify it on the server side, with this jsessionid, i want to access all those objects which have been created for that jsessionid..

These calls are not context specific, we are making absolute HTTP calls..

Any help would be highly appreciated..
Thanx in Advace.

Shridhar..
Deepak Kaimal
Greenhorn

Joined: Aug 30, 2005
Posts: 13
Sridhar,
The jsessionid is a unique identifier that is used by the web container as a pointer to your session. As such, the session id is usually persisted on the client and retrieved by the server either through a cookie or through URL rewriting.
The first time you create a session on the server, a session id is returned to the client. You must pass this to the server for subsequent calls. How you pass this depends on how the server expects to receive it.
If it was part of a cookie, you will need to send it back as part of the "Cookie" header. If it was through URL rewriting, you will need to set it as part of the query string.
For the second part of your question there is no way to explicitly retrieve a handle to a session knowing the session id. This was previously possible via the getSession() method on the HttpSessionContext class. As of Servlet API 2.1, this class is deprecated for security reasons.
In my opinion you have two options
1. Try and retrieve the session ID on your client side and send it back to the server. On the server side use sessions normally (request.getSession()). If you use a standard client library like Apache common's HTTPClient, this should happen very cleanly.
2. Use your own session identifier and manage the sessions yourself on the server independant of the container's session management. I think this is a very dirty way to do things.
 
jQuery in Action, 2nd edition
 
subject: How to use jsessionid while making HTTP calls??