• Post Reply Bookmark Topic Watch Topic
  • New Topic

Diff between request and session attribute  RSS feed

 
Matt Kim
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm fairly new to web development. My question is, what's the difference between a session attribute and a request attribute?
And when should they be used?
Regards,
Matt
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request scope only exists for the lifetime of a single request/response cycle. The session exists for the duration of a user session. Therefore request attributes are only available during a single request, while session attributes remain available for the duration of the session.
you should use request in favor of session attributes when the attribute does not need to "live" beyond the scope of the current request. Session attributes, should be used for data that needs to be available across request boundaries.
Btw, there is also an "application" scope whose attributes are available for the entire duration of the application and can be used for data that needs to be cross-request, but is not specific to a user session.
 
Matt Kim
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, thanks Bear!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!