Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
13.4 Sharing Beans
305
page
This is the default value. It indicates that, in addition to being 
bound to a local variable, the bean object should be placed in the 
PageContext
 object for the duration of the current request. In 
principle, storing the object there means that servlet code can 
access it by calling 
getAttribute
 on the predefined 
pageContext
 variable. In practice, beans created with 
page
scope are almost always accessed by 
jsp:getProperty
, 
jsp:setProperty
, scriptlets, or expressions later in the same 
page.
application
This very useful value means that, in addition to being bound to a 
local variable, the bean will be stored in the shared 
ServletContext
 available through the predefined 
application
 variable or by a call to 
getServletContext()
. 
The 
ServletContext
 is shared by all servlets in the same Web 
application (or all servlets in the same server or servlet engine if 
no explicit Web applications are defined). Values in the 
ServletContext
 can be retrieved by the 
getAttribute
method. This sharing has a couple of ramifications. 
First, it provides a simple mechanism for multiple servlets and 
JSP pages to access the same object. See the following subsection 
(Conditional Bean Creation) for details and an example. 
Second, it lets a servlet create a bean that will be used in JSP 
pages, not just access one that was previously created. This 
approach lets a servlet handle complex user requests by setting 
up beans, storing them in the 
ServletContext
, then forwarding 
the request to one of several possible JSP pages to present results 
appropriate to the request data. For details on this approach, see 
Chapter 15 (Integrating Servlets and JSP).
session
This value means that, in addition to being bound to a local 
variable, the bean will be stored in the 
HttpSession
 object 
associated with the current request, where it can be retrieved 
with 
getValue
. Attempting to use 
scope="session"
 causes an 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved