This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i store a bean in a session ?  RSS feed

 
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")
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!