• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP:USEBEAN SCOPE:

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I was thinking redirect. Thanks for the distinction!
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This url should makes things clearer...
http://www.jguru.com/faq/view.jsp?EID=53309


Mahesh
reply
    Bookmark Topic Watch Topic
  • New Topic