BGColor.jsp) from the CWP book.It illustrates JSP expressions (<%= expression %> and scriptlets (<% code %>).
CoreWebProgramming directory under %TOMCAT-HOME%/webapps (although it need not be within the TOMCAT-HOME directory); cwp directory under the CoreWebProgramming directory; BGColor.jsp to %TOMCAT-HOME%/webapps/CoreWebProgramming/cwp%TOMCAT-HOME%/conf/server.xml file so that you can access BGColor.jsp as an html file. To do that, I made the following entry in the %TOMCAT-HOME%/conf/server.xml file:
<Context path="/CoreWebProgramming"
docBase="webapps/CoreWebProgramming"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
BGColor.jsp page at http://localhost:8080/CoreWebProgramming/cwp/BGColor.jsp
http://localhost:8080/CoreWebProgramming/cwp/BGColor.jsp?bgColor=orange or
http://localhost:8080/CoreWebProgramming/cwp/BGColor.jsp?bgColor=ffaa33.
doGet() method, with the HTML corresponding to out.println() statements.
if statement. Here are the original and the revised if statements.
<%
if (hasExplicitColor) {
out.println("You supplied an explicit background color of " +
bgColor + ".");
} else {
out.println("Using default background color of WHITE. " +
"Supply ?bgColor=, where <color> is either " +
"a standard color or an RRGGBB value, " +
"if your browser supports X11 color names.");
}
%>
<%
if (hasExplicitColor) {%>
You supplied an explicit background color of <%= bgColor %>.
<%} else {%>
Using default background color of WHITE.
Supply ?bgColor=<color>, where <color> is either
a standard color or an RRGGBB value,
if your browser supports X11 color names.
<%}
%>
<%= bgColor %>) embedded within the HTML, which is embedded within a scriptlet.
<%! standard java declaration %>. See page 976 in the book (or example 20.3). Note that a number of variables are predefined. (See page 977 in the book.) These include request, response, session, etc.
<%@ page import="java.io.*" %>). See example 20.4, p. 980. For an example of an import and a declaration that includes a declaration of a method, see ImportAttribute.jsp.