Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
10.3 JSP Scriptlets
241
Figure 10 4 Result of BGColor.jsp when accessed with a bgColor parameter 
having the X11 color value papayawhip.
Using Scriptlets to Make Parts of the JSP File 
Conditional
Another use of scriptlets is to conditionally include standard HTML and JSP
constructs. The key to this approach is the fact that code inside a scriptlet
gets inserted into the resultant servlet's 
_jspService
 method (called by
service
) exactly as written, and any static HTML (template text) before or
after a scriptlet gets converted to 
print
 statements. This means that script 
lets need not contain complete Java statements, and blocks left open can
affect the static HTML or JSP outside of the scriptlets. For example, con 
sider the following JSP fragment containing mixed template text and script 
lets.
<% if (Math.random() < 0.5) { %>
Have a nice day!
<% } else { %>
Have a lousy day!
<% } %>
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