Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 964
user717236 Avatar asked Aug 31 '12 18:08

user717236


2 Answers

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.

like image 178
jma Avatar answered Nov 15 '22 06:11

jma


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.

like image 1
Vaibhav Gupta Avatar answered Nov 15 '22 06:11

Vaibhav Gupta