Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
292
Chapter 13 Using JavaBeans with JSP
JSWDK 1.0.1:
install_dir/webpages/WEB INF/servlets/lima/Fordhook.cl
ass
Java Web Server 2.o:
install_dir/classes/lima/Fordhook.class
The JSP files that use bean classes don't need to be installed anywhere spe 
cial, however. As is usual with JSP files on a JSP capable server, they can be
placed anywhere that normal Web pages can be.
13.2 Example: StringBean
Listing 13.1 presents a simple class called 
StringBean
 that is in the 
core 
servlets
 package. Because the class has no public instance variables (fields)
and has a zero argument constructor since it doesn't declare any explicit con 
structors, it satisfies the basic criteria for being a bean. Since 
StringBean
 has
a method called 
getMessage
 that returns a 
String
 and another method
called 
setMessage
 that takes a 
String
 as an argument, in beans terminology
the class is said to have a 
String
 parameter called 
message
. 
Listing 13.2 shows a JSP file that uses the 
StringBean
 class. First, an
instance of 
StringBean
 is created with the 
jsp:useBean
 action as follows:
After this, the 
message
 property can be inserted into the page in either of
the following two ways:
<%= stringBean.getMessage() %>
The 
message
 property can be modified in either of the following two ways:
property="message" 
value="some message" />
<% stringBean.setMessage("some message"); %>
Figure 13 1 shows the result.
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