Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Behavior (new to it)

 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a little confused.

I have a simple servlet that creates a HttpSession, the class is below. My question is this. If I open my browser and the html page calls the servlet, the servlet creates a session and adds a cookie with the session ID. I close my browser, open a new browser and call my servlet again, however the servlet creates a new session and new session ID. Is this normal? I was sort of under the impression that if you opened a new servlet, and that servlet called request.getSession(), the existing(original) session would be found.
Please clarify if possible.

Thanx

 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The cookies used here, are session cookies, and these die together with
your browser instance. It is very unusual to have a session that
survives a re-opening of the browser. If you want to do that you
might consider the use of a "real" cookie that contains the uniqie
id you get from [session].getId().

To revitalize the session you could do a first connect to the servlet,
this will read the cookie and redirect you to the servlet for a second
time using the URL plus the sessionID in the form of

host.tld;jsessionid=[yourid]?what=ever&plus=your_dog

The session ids have the advantage that your user can let them active
if he decides to join the dilletant paranoia and switch off cookies
(my opinion might be biased her, argh)


J.

[ April 19, 2005: Message edited by: Jeffrey Spaulding ]

[ April 19, 2005: Message edited by: Jeffrey Spaulding ]
[ April 19, 2005: Message edited by: Jeffrey Spaulding ]
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

I see what you mean and understand.

Thanks so much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic