File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Session in a website with html pages and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session in a website with html pages and servlets" Watch "Session in a website with html pages and servlets" New topic
Author

Session in a website with html pages and servlets

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi all,

How can we track the session in a website if the user has logged in using the servlet and then transversed through html pages of the site and then comes back to a servlet..

Will the same session that i created in the login servlet...

HttpSession...

be accessible in the latter servlet even after the user has acccessed the intermediate html pages...

Regards
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yes, the session will still exist as long as the user is using the same browser instance
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thank you David...

Suppose i open a popup window in which i call a servlet that displays a Pdf in the popup...will the session exist in that servlet....

If not how to check the session...in the new servlet requested through the popup...

Regards
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Each session is tied to a "web application" - see the Javadocs for HttpSession or read the Servlet API - download it here.
All servlets in a "web application" share the same ServletContext.
Bill
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I think it's easier with a short description of how sessions are supported...

When you send the first request to a web site, the site decides to initiate a session (to remember this user and track their usage of the site) and sends a session token back to the client. Any request sent from the client back to that site will contain that token, just like saying 'Hey, remember me?'.

The client doesn't distinguish between sending requests for static or dynamic content as it really doesn't know. It just keeps sending requests and including the token, the server is free to make use of the token if it wants or can ignore it.

With session tokens, the client will continue sending the token until one of several things occurs. If the browser is closed the session is lost. If the token expires it no longer gets sent. If the server 'rejects' the token, the client stops sending it, although this is a special case of the previous case, since the server instructs the client to expire the token immediately.

Coming back to your second question, a pop-up window is created by the original browser instance and also passes the token to the server. There is a bug in some versions of IE where this doesn't work, but the general rule is that pop up windows don't affect the behaviour.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thank you DAvid and William....

that was quite resourcefuL.inputs..

Regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session in a website with html pages and servlets