File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes scope resolution  in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "scope resolution  in JSP" Watch "scope resolution  in JSP" New topic

scope resolution in JSP

Anant Kadiyala

Joined: Aug 29, 2001
Posts: 24
Can someone explain the difference between 'page scope' and 'request scope'? In this book I am reading it says, " The request scope is for objects that need to be available to all pages processing the same request".
I am confused by this statement. Lets say I have page A that has a 'Next' button that takes me to page B. Similarly the 'Next' on page B takes me to page C and so on.. Now, isn't the request made to the web server different from Next on page A to that of the Next on page B?! If that is true, how can we have the "same request" for multiple pages?

IBM Certified in Object-Oriented Analysis and Design with UML
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Page scope is the smallest, an object in page scope can't be seen if you forward the request. It has nothing to do with your example of HTML pages, it refers to a JSP page.
An object in request scope only lives during a single request - response cycle.
author of:
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
If you set a page-scope attribute and then forward the request, the attribute will not be visible to the forwarded page. If you set a request-scope attribute, it will be visible to the forwarded page. I believe pages included via jsp:include work the same way, but I'm not 100% sure.
John Juneja

Joined: Sep 09, 2001
Posts: 1
That helps!! Thanks a lot :-)
I agree. Here's the link:
subject: scope resolution in JSP
It's not a secret anymore!