Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving info in a session  RSS feed

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. here's what I need. I want to be able to cache my information along the way as people go through my web site answering questions. I want the information to be saved in the session and destroyed when they quit. Can you help me out w/this? ...
How would I do this using JSP/Servlets and sessions.
Thanks
Dale

------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly what the HttpSession class is intended to be used for. You could store a Hashtable in which the question answer is keyed by the question name. The servlet engine automatically keeps track of session objects for you using cookies.
HttpSession session = request.getSession( flag );
You get a session from the request object, if flag= true, a new session will be created if none exists, otherwise you get null if none exists.
A HttpSession acts like a Hashtable with objects stored by name, the only limit is available memory.
In a jsp there is a session object that is handled automatically.
Any good book on servlets and JSP will fill in the details.
Bill
------------------
author of:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!