File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how  session works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "how  session works?" Watch "how  session works?" New topic

how session works?

rakesh mittal

Joined: Oct 10, 2005
Posts: 27
can anybody tell me how session works
what is the use of session id.
please help me
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215

Sessions are much like a Map that the container stores on a client by client basis in another Map. To identify which session belongs to which client the container generates a unique id, (I don't know the method that the container uses to generate the id) which it uses as a key to the Map it keeps internally of all the sessions. The id is passed to an from the client either in a cookie or as part of the request in a parameter.

When the Servlet or Jsp code requires a session attribute it gets the appropriate session object from the container (note this is already done for you in JSP's) which in turn goes to its map and uses the jsessionid cookie value (or request paramter value) as the key to get the appropriate session, which it then passes back.

The Session itself is mainly used to store attribues for a client, ie all the goods in their shopping cart, etc.

I should add that this is vastly simplified for the sake of a simple explanation.

I agree. Here's the link:
subject: how session works?
It's not a secret anymore!