• 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

Saving info in a session

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
I didn't say it. I'm just telling you what this tiny ad said.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic