Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
290
Chapter 13 Using JavaBeans with JSP
double quotes, and noncontainer elements should end the tag with 
/>
, not 
just 
>
.
There are also a few character sequences that require special handling in
order to appear inside attribute values:
To get 
'
 within an attribute value, use 
\'
.
To get 
"
 within an attribute value, use 
\"
.
To get 
\
 within an attribute value, use 
\\
.
To get 
%>
 within an attribute value, use 
%\>
.
To get 
<%
 within an attribute value, use 
<\%
.
Accessing Bean Properties
Once you have a bean, you can access its properties with 
jsp:getProperty
,
which takes a 
name
 attribute that should match the 
id
 given in 
jsp:useBean
and a 
property
 attribute that names the property of interest. Alternatively,
you could use a JSP expression and explicitly call a method on the object that
has the variable name specified with the 
id
 attribute. For example, assuming
that the 
Book
 class has a 
String
 property called 
title
 and that you've cre 
ated an instance called 
book1
 by using the 
jsp:useBean
 example just given,
you could insert the value of the 
title
 property into the JSP page in either
of the following two ways:
<%= book1.getTitle() %>
The first approach is preferable in this case, since the syntax is more acces 
sible to Web page designers who are not familiar with the Java programming
language. However, direct access to the variable is useful when you are using
loops, conditional statements, and methods not represented as properties.
If you are not familiar with the concept of bean properties, the standard
interpretation of the statement  this bean has a property of type 
T
 called 
foo
is  this class has a method called 
getFoo
 that returns something of type 
T
 and
has another method called 
setFoo
 that takes a 
T
 as an argument and stores it
for later access by 
getFoo
.  
Setting Bean Properties: Simple Case
To modify bean properties, you normally use 
jsp:setProperty
. This action
has several different forms, but with the simplest form you just supply three
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