Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Diff between request and session attribute  RSS feed

 
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
 
Author and ninkuma
Marshal
Posts: 66807
168
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!