Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i store a bean in a session ?

 
Trader Joey
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing an application similar to the often refered to shopping cart example. After the validating the user by checking his name-password entry in the database, the user can select items from different pages. Good programming rules say that a servlet should not genertae HTML pages. So I want to store the user name and password ( stored in the bean ) in a seesion for that user. How do I do that ?? Please reply.
Thanks
 
Bhupinder Dhillon
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use one of the following methods (depending on which version of servlet api your server uses)..
Session.putValue(String "anyName", Object obj)
or Session.setAttribute(String "anyName", Object obj)
To retrieve the object from the session...
Object obj = (Object)Session.getValue("anyName") or
Object obj = (Object)Session.getAttribute("anyName")
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic