• 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

what is session ?

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can Some one explain what session means servlet?
When it starts and when it ends ? or
When the session id is created and destroyed ?

"I think, the session or the session id will be the same,
as long as you send the request to the servlet from the same browser instance", Am I correct ?

thanks
siva

[ February 03, 2006: Message edited by: Siva kandasamy ]

[ February 03, 2006: Message edited by: Siva kandasamy ]
[ February 04, 2006: Message edited by: Siva kandasamy ]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First of all let me tell you why the session is needed. HTTP is a stateless protocol. So, it can't be used to store a state. Session tracking is the answer for that. Now, there are two techniques of session tracking. One is Cookies and the other is by the mean of HttpSession. The second one is widely used which you can say kind of new concept of storing a state of a user session.

Whenever a client sends a request to the server for the first time, a new session instance is created. Here, client means a new instance of a browser. If you've already requested and you're opening a new browser, it'd create a new session object for that browser. Or, if you press ctrl + n to the existing window, a new session would not be created as it was initiated from the previous browser. Now, whatever data being stored by the mean of session, is kept on the server. More preciously, the servlet container maintains a kind of hashmap where the key would be a session id and the value would be an HttpSession object. No need to tell that each id is associated with each "new instanced" browser. Now again there are two techniques of storing this id. First by cookie AND by URL re-writting or hidden elements.

A session id is maintained to retrive session information lied on the server. Everytime, whenever the client request for any resource, along with the request parameters, the session id is being passed as an extra parameter. So, on the server end, the object against that id is being searched from that hashmap and that object is returned if any operation is being made on that session.

An HttpSession object stored on the server is invalidated after a session timeout time. On tomcat, session timeout is 30 mins. So, say if a session is not being accessed, rather from the same browser, for 30 mins, any request has not come, the session would be destroyed. To destroy an HttpSession programatically, invalidate() method can be used.

I hope this would help . There are a lot material available on session. You can search on the web and have a more clear idea.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic