1)When you say request.getSession in servlet... ,container creates session object
(Assume its id is 100).. Container stuffs that id in cookie and sends that cookie
as response header....
2)when you request another page... what browser does in back ground is,, the
session id which it received will be sent in the second request..., so when
you say request.getSession ,container checks the session id 100 recieved
from the browser and understands that there is already an existing session
100, so it won't create new session,it creates existing session object with id
100..(Suppose if you say session.setAttribute("name","anil");
3)When you request another page browser sends to server the session id
it received (100),and if you call request.getSession ,server retrieves
the session object with id 100 and gives it to you. That means that
session will have the attribute name with value anil. because this is
pre existing session.
---------------------------
If
another person from different session issues a request... container
won't receive any session id from browser because this is new
request,container creates another
session for second person.. say its id is 200, and pass it to second persons browser in the form of cookie
second person requests another page,browser in back ground sends 200 (session id)
to browser container retrieves session object with sesion id 200.. observe that this
session doesn't contain attribute name with value anil. because 200 session is different from session one...(100).
Container and browser does the background work...
When you say request.getsession,container checks if it has received session id
from browser,if this is the first request, container won't receive session id..
so container creates new session and sends that id to browser in response(background work)
From then onwards,whenever you make new request browser sends the session
id and container gives the pre existing session instead of creating new one...
No comments:
Post a Comment