Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Request Scope Question

 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,
Thanks for clearing up the request scope for me. I appreciate the quick response.
J
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic