Java Reference
In-Depth Information
Figure 18−4. The output of portal.jsp
The portal.jsp page also demonstrates other useful JSP programming techniques.
Like the login.jsp page, it has a <%@taglib%> directive and makes heavy use of the
custom <decor:box> tag. It also uses the <%@include%> directive to statically
include the forcelogin.jsp page at compile time. As we saw earlier, this forces the
user to log in before any output is displayed. In addition, portal.jsp uses the
<jsp:include> tag once at the top of the page to dynamically include the output
of the Hello servlet and twice more at the end of the page to include output from
the Counter servlet.
Note the code portal.jsp uses to dynamically generate the HTML <select> tag that
lists color choices. This code surrounds HTML tags with Java scriptlets that form
the beginning and end of a Java for loop. Each time through the loop, HTML tags
are output. However, since the HTML tags include JSP expressions ( <%= . . . %> ),
they expand differently each time through the loop. This is a relatively common
and powerful JSP programming technique, although the tight coupling of Java and
HTML code is not ideal.
Finally, note that portal.jsp includes an HTML form that displays a logout button.
When clicked, this button loads the servlet servlet/logout . You'll see how this
Logout servlet works in Example 18-8.
Search WWH ::




Custom Search