Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get/set attribute

 
Rang Sar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a Action class and it forwards to a jsp. I set a Object in request scopt and obtain it in jsp and again set it to request scope. Now in jsp i have a button, when clicked this goes to another Action Class. I am not able to get the object from request. it is always null.

-Rang
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ranga S",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ranga S:

I have a Action class and it forwards to a jsp. I set a Object in request scopt and obtain it in jsp and again set it to request scope. Now in jsp i have a button, when clicked this goes to another Action Class. I am not able to get the object from request. it is always null.


That is correct. The request goes out of scope when the response is returned to the client.

I suggest reading this article for a better understanding of the life-cycle of a JSP request.
 
Rang Sar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me is there any solution to this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ranga S", my request that you adjust your display name was not a suggestion. Valid display names are a requirement for participation on the JavaRanch. Please re-read my request and change your display name prior to your next post.

bear
JavaRanch Sheriff
[ January 28, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

To persist a scoped variable across multiple requests, one means is to place the scoped variable into session scope rather than request scope.

When doing so, take care to "clean up" after yourself as sessions only go out of scope when they timeout, so you may end up with a lot of wasted memory if you aren't careful with session data.
 
Rang Sar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
Without putting to session is there any way where I can manage with requests only ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could propogate the values by writing them as hidden elements in the page's form so that they will be re-submitted on the next request.

That's more work and means everything needs to be serialized to string values.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic