Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Scopt and Page Scope

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the difference between the Request Scope and the Page Scope?
Also, does either one of these have the object in the scope survive until it reaches the servlet again?
Dale
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The primary difference is that attributes in request scope will survive a transition to another page via a forward, while page attributes will not. Similarly, request attributes are available to included pages, while those in page scope are not.
Both go out of scope when the response is sent to the client.
hth,
bear
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So.. Lets go over an example...
I'm in my servlet and put objectA into the request
The page is then dispatched
The user goes over the info in the page and then hits submit and the page is sent back to the servlet.
The servlet gets the page. Looking in the session, I should still see objectA.
Correct??
When I NOW dispatch my next page, that first request will die [the one that contained objectA]. Correct???
-Dale
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dale, no that's not quite right. HTTP is a stateless protocol, so once the response gets sent to the client, all request information is lost.
In your example, objectA goes out of scope when the JSP page is sent to the user.
If you want the lifetime of objectA to survive a single request/response cycle your servlet should put the object into session scope (not request scope). The whole purpose of the session is to allow object to persist in this way.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic