This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Scope Question

 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
William,
Thanks for clearing up the request scope for me. I appreciate the quick response.
J
 
Shailendra Bade
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic