• 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

Storing information in session

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic