• 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

request attributes

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the advantages of using request attributes vs session in transporting data?

Thank,
Dave
 
Sheriff
Posts: 67747
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
They go out of scope when the corresponding response is sent to the client.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are only in scope throughout the life of the request, where as session attributes persist across requests. Attributes should live for the shortest amount of time you can get away with or you may end up with hard to track down errors and spaghetti code where you have to forcibly remove a session attribute when you've finished with it (because you should have put it as a request attribute).

Liken it to;
Application scope -> Global Variable (public static)
Session scope -> Instance variable (class member)
Request scope -> Method local variable
 
Dave Chawan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks both for all your help.

If I want to preserve the request scope, I can use forward from RequestDispatcher to keep forwarding the data to different resources. Is this correct?

Dave
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes with forward() request preserve its state.
 
Dave Chawan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to the forum.

So nice to know my questions were answered so promptly.

I'm really glad to be a new javaranch community member.

Thanks again for all your help!

Dave
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic