• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Behavior (new to it)

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

I see what you mean and understand.

Thanks so much
reply
    Bookmark Topic Watch Topic
  • New Topic