Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing MySQL data in http session attribute?  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it feasible to store SQL user data (name, age address..etc) in session attributes in servlet/JSP after user login? Is it common practice?, should I use cookies instead? what is a common practice
 
author & internet detective
Marshal
Posts: 38250
623
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hayder,
Welcome to CodeRanch!

Storing info that is used on many pages makes sense to store in the session such as the user's name. I can't imagine you use the address that often so it might be better to look it up each time.
 
hayder ma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you .
 
Bartender
Posts: 19454
88
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store anything you want quick access to in the HttpSession. Doesn't matter where it comes from, SQL, LDAP, radio messages from outer space, whatever. But remember that those stored items occupy memory, so the total RAM requirements for the server are going to multiply on the order of #concurrentsessions X bytespersession, Do remember, however, that if the original data source changes values that the session data won't follow the changes.

Some servers - including database servers - may have local data caching. That can be almost as fast as directly storing in the session and may even work better if multiple sessions are concurrently reading and updating.

Generally speaking, don't store sensitive data in cookies. Cookies can be hacked on the client side. Plus sending cookies back and forth adds to the total amount of network traffic. For best response and greatest security, data should remain on the server.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!