Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
306
Chapter 13 Using JavaBeans with JSP
error at page translation time when the 
page
 directive stipulates 
that the current page is not participating in sessions. (See 
Section 11.4,  The session Attribute. )
request
This value signifies that, in addition to being bound to a local 
variable, the bean object should be placed in the 
ServletRequest
 object for the duration of the current request, 
where it is available by means of the 
getAttribute
 method. 
This value is only a slight variation of the per request scope 
provided by 
scope="page"
 (or by default when no 
scope
 is 
specified).
Conditional Bean Creation
To make bean sharing more convenient, there are two situations where
bean related elements are evaluated conditionally.
First, a 
jsp:useBean
 element results in a new bean being instantiated
only if no bean with the same 
id
 and 
scope
 can be found. If a bean with the
same 
id
 and 
scope
 is found, the preexisting bean is simply bound to the vari 
able referenced by 
id
. A typecast is performed if the preexisting bean is of a
more specific type than the bean being declared, and a 
ClassCastExcep 
tion
 results if this typecast is illegal.
Second, instead of 
you can use
statements
The point of using the second form is that the statements between the
jsp:useBean
 start and end tags are executed only if a new bean is created,
not if an existing bean is used. This conditional execution is convenient for
setting initial bean properties for beans that are shared by multiple pages.
Since you don't know which page will be accessed first, you don't know which
page should contain the initialization code. No problem: they can all contain
the code, but only the page first accessed actually executes it. For example,
Listing 13.7 shows a simple bean that can be used to record cumulative
access counts to any of a set of related pages. It also stores the name of the
first page that was accessed. Since there is no way to predict which page in a
set will be accessed first, each page that uses the shared counter has state 
ments like the following:
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