6

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.

user717236
  • 4,959
  • 19
  • 66
  • 102

3 Answers3

10

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.

jma
  • 201
  • 1
  • 2
  • Okay, yes, that's exactly what I was looking to see if I can still do. Thank you. I thought that passing jsessionid to the URL makes it part of the querystring. – user717236 Aug 31 '12 at 18:51
1

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.

Jasonw
  • 5,054
  • 7
  • 43
  • 48
Vaibhav Gupta
  • 1,035
  • 1
  • 8
  • 16
0

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.

amate
  • 1