aspose file tools*
The moose likes Servlets and the fly likes Session Behavior (new to it) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Behavior (new to it)" Watch "Session Behavior (new to it)" New topic
Author

Session Behavior (new to it)

Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97
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



Jimmy Die
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
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

Joined: Nov 20, 2003
Posts: 97
Yes,

I see what you mean and understand.

Thanks so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Behavior (new to it)
 
Similar Threads
Session and cookies
Problem with session.invalidate()
Servlet becomming slow
Servlet becomming slow
How to disable cookies