wood burning stoves 2.0*
The moose likes JSP and the fly likes Storing information in session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Storing information in session" Watch "Storing information in session" New topic
Author

Storing information in session

Martin Lira
Ranch Hand

Joined: May 26, 2004
Posts: 97
Hi everybody!
I have a web application that needs to store some information in the session for the current user, eg. username, dob, address. One way of doing this would be storing each value as
session.setAttribute("username","xyz")
and then retrieving the info by session.getAttribute("username").
Another way would be creating a WebUserBean class that has member variables String userName, dob etc and storing it as
session.setAttribute("webuser",new WebUserBean(xyz,dob)).
Which of these methods will use less memory/resource? or which will give better performance?

Thanks,
Martin
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
If you must store information on a per user basis, I'd just code something that makes object oriented sense. For example, create a ShoppingBag object and save it on the session rather than put every item in the shopping bag as a name/value pair on the session.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Which of these methods will use less memory/resource? or which will give better performance?


This is the wrong question.

The question should be "Which of these methods will create the better-structured application?"

My answer to that question would be to abstract the values into a single concept and store that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: Storing information in session
 
Similar Threads
how to use session variable in struts 2
Accessing session or application attributes from within a JavaBean
Session tracking in servlets
how to get the username from session?
regarding session transfer from servlet to jsp