• Post Reply Bookmark Topic Watch Topic
  • New Topic

attribute is lost  RSS feed

 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp file. I put an attribute to a request object by
request.setAttribute("obj", obj).
Now when I submit a handlerbean is called. When I retrieve that attribute by request.getAttribute() there it's null. I dont know why or is it because applicable only on RequestDispatcher method.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you submit, you are initiating a new request. Attributes placed on the previous request will not be available.
For attributes to persist across submissions, they must be placed in either session or application scope.
 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, but am I right that if I use the RequestDispatcher method it will be availabe to the page the dispatcher refers?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you forward to another resource via a request dispatcher, the forward takes place in the same request context, so yes, a request attribute remains available over a forward.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!