This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP:USEBEAN SCOPE: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP:USEBEAN SCOPE:" Watch "JSP:USEBEAN SCOPE:" New topic
Author

JSP:USEBEAN SCOPE:

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hello,
What is the difference between the different scopes available & when are they used?
for e.g te scope page/session/application/request what is main difference between them & under which condition are they used?

thanks,
Trupti
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
Page is the same as request, the elements for the page are only available at the time the page is loaded, or upon each request.
Session means the information contained has visibility across multiple pages, for as long as the users session lasts. You might need this scope for a shopping cart-type application or wherever users need to persist their info across many pages.
Application means universally accessible. All clients using your web application have visibility. You might use this scope to share a database connection among your users.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65


Page is the same as request, the elements for the page are only available at the time the page is loaded, or upon each request.

Not exactly. Beans declared at request scope will be available in forwarded pages. Those declared at page scope will not.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
Do you mean to say that when you forward to a different jsp page, you can retrieve reference to objects that were part of the request that you were forwarded from? When it comes to "scope", I really don't see much distinction between page and request. Can you illustrate, Bear?
TIA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65

Absolutely. When you forward from one servlet to another (remember that JSPs are just servlets in drag) you remain within the context of the same request. That means that all request context elements, including both request parameters and attributes, are available within the forwarded page.
Therefore, beans that have been placed into the request scope are available across all forwarded pages.
This is actually a very important concept for the MVC/Model 2 architecture, as well as useful patterns like Front Controller.
Note, that this is not the case when a redirect is performed. In that case, the browser issues a new request, so context from the original request is no longer available.
hth,
bear
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
Yes, I was thinking redirect. Thanks for the distinction!
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Hi,
This url should makes things clearer...
http://www.jguru.com/faq/view.jsp?EID=53309


Mahesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP:USEBEAN SCOPE:
 
Similar Threads
Bean Scope
difference between page and request
default scope
What is the difference between page and request scope
Application and Request Scope