Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request attributes

 
Dave Chawan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the advantages of using request attributes vs session in transporting data?

Thank,
Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They go out of scope when the corresponding response is sent to the client.
 
Darren Edwards
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes with forward() request preserve its state.
 
Dave Chawan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic