Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
10.3 JSP Scriptlets
239
As an example of executing code that is too complex for a JSP expression,
Listing 10.2 presents a JSP page that uses the
bgColor
request parameter to
set the background color of the page. Some results are shown in Figures
10 2, 10 3, and 10 4.
Listing 10.2 BGColor.jsp
Color Testing
<%
String bgColor = request.getParameter("bgColor");
boolean hasExplicitColor;
if (bgColor != null) {
hasExplicitColor = true;
} else {
hasExplicitColor = false;
bgColor = "WHITE";
}
%>
Color Testing
<%
if (hasExplicitColor) {
out.println("You supplied an explicit background color of " +
bgColor + ".");
} else {
out.println("Using default background color of WHITE. " +
"Supply the bgColor request attribute to try " +
"a standard color, an RRGGBB value, or to see " +
"if your browser supports X11 color names.");
}
%>
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
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