• Post Reply Bookmark Topic Watch Topic
  • New Topic

setAttribute

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I was going through some code and I came across this:



What does it do ? And why use it ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This creates a request-scoped variable named user.

Frequently this will be done so that the scoped variable is available to the next resource in the request chain, usually a JSP.

Scoped variables are an essential ingredient in creating modern Java web applications. It is important to understand them thoroughly.
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request attributes are very similar to what request parameters are. Difference is that parameters come along with request and they can't be set on the server side, while attribute setting is done on the server side. As mentioned by Bear they are supposed to be used by next resource, who is going to process the request further. This is one of the many ways of passing some values from one resource to another on server side.
 
Avyaya Avi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It just exemplifies a bean being set to the request attribute.

It's primary purpose if to serve the application request.So, the bean is being set into an attribute which carries the information in the bean to the next 'request-serving-code' or the code which would work on the info in the attribute on the server side and add some more details if required.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!