aspose file tools*
The moose likes Servlets and the fly likes Request Scope Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Scope Question" Watch "Request Scope Question" New topic
Author

Request Scope Question

Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I am having difficulty maintaining the state of an object between two pages, say a.jsp and b.jsp. I only want the bean in scope for these two pages.
Page a.jsp presents a form and instantiates MyBean myBean using request scope. During instantiation of myBean, some properties are set. When the user hits submit, b.jsp is called.
b.jsp also uses myBean in request scope, and sets any properties sent via the form.
Now my question is, why isn't the state of the myBean in b.jsp the same as the state of myBean in a.jsp. I have a property that is set in a.jsp (and not corresponding to a form field), that is no longer set when b.jsp uses myBean.
I know that if I had used session scope, this wouldn't be a problem, but because of the application, session scope shouldn't be used with this bean. I also know that I could just pass the properties in hidden form fields, but I was hoping there was a more elegant way to do this.
Again, I thought that 'request' scope might be the answer, but it doesn't seem to be working. I've RTFM but I must be missing something with regards to request scope. Anyone have any ideas?
TIA,
J
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
What you want is session scope, not request scope.
Request scope is used for objects that you want to accompany a forwarded request (HttpServletRequest object). Since the life of a request object is over after the response has been sent, naturally the next request can't see the same bean.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
William,
Thanks for clearing up the request scope for me. I appreciate the quick response.
J
Shailendra Bade
Greenhorn

Joined: Jul 04, 2000
Posts: 22
If request is dying out after submitting(it appears from William's reply, i am not sure) the page then what is the difference between page scope and request scope.


Shailendra Bade<BR>Mumbai, India<BR>Mail to: bades@vsnl.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Request Scope Question