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


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

Request Scopt and Page Scope

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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

Joined: Jan 10, 2002
Posts: 60074
    
  65

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request Scopt and Page Scope
 
Similar Threads
Doubt Regarding implicit objects
page scope
jsp + thread safe
bean in or out scope?
Difference between request Scope and Page Scope?