• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Maintain Session

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If HTTP is staleless protocol then how does it maintain Session through HttpSession

Thanks,
aakash
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server uses a session cookie (stored in the user's browser), or, sometimes a url parameter to match the user up to a session object (stored in memory on the server).
 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben,
With cookie and Url paramter we can maintain session indirectly.
But my query is as Http is a staless protocol then how does we can maintain a sesion by setting values in HttpSession, then how does in this HTTP protcol handle it.

Thanks,
aakash
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, HTTP is stateless. That means the server has to check for a sessionId in every request that comes in (either as a cookie header or as a url parameter).
If it finds one, it checks to see if there is an object, stored in session, with a matching id. If not, then it creates a new object and sends the ID back to the browser in the response.

The HTTP protocol doesn't handle it. The servlet container mimicks a stateful session with this technique.

If you're asking how to save objects in session, read up on the HttpSession's
getAttribute and setAttribute methods.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic