user717236
user717236

Reputation: 5039

How do I retrieve the jsessionid from URL in JSP?

I know how to pass the jsessionid to the URL. I encode the url, which will look like this:

mysite.com;jsessionid=0123456789ABCDEF (http)

Does there exist a built-in method to retrieve the jsessionid from the URL, using Java? I found this method in the javadocs, isRequestedSessionIdFromURL, but it doesn't help me actually retrieve the value. Do I have to build my own retrieval method?

Thank you.

Upvotes: 6

Views: 8098

Answers (3)

amate
amate

Reputation: 1

session.getId() should be able to get you the session id. WLS would be doing the actual parsing of the URl to retrieve the session id once it identifies that the session id is not stored in the cookie or in hidden form fields. The sequence usually is Cookie - URL - Hidden Form Fields.

Upvotes: 0

Vaibhav Gupta
Vaibhav Gupta

Reputation: 1095

Cookieless sessions are achieved in Java by appending a string of the format ;jsessionid=SESSION_IDENTIFIER to the end of a URL. To do this, all links emitted by your website need to be passed through either HttpServletRequest.encodeURL(), either directly or through mechanisms such as the JSTL tag. Failure to do this for even a single link can result in your users losing their session forever.

Upvotes: 1

jma
jma

Reputation: 201

JSP has an implicit session object, similar the request object. It is an instance of java.servlet.http.HttpSession, which has the method getId().

So, you should be able to just do session.getId() in your JSP page.

Upvotes: 10

Related Questions