Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.setAttribute vs request.setAttribute

 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a clarification :-). Im just confuzed what and to when to use those 2 the same method.....
Correct me if Im wrong...
They have the same objective (to keep a certain value)but the difference is the scope of their attribute values? Am I right? I Thanks.
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic difference between these 2 methods is the scope or lifetime of the attribute you are setting.
If you set an attribute on the request it is only available for that specific request. If you set it on the session it is available for that request and all subsequent requests by the user using the session (i.e. until the session expires or you explicitly remove the attribute)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic