Learn Java for Web Development

(Tina Meador) #1
CHAPTER 3: Best Practices in Java EE Web Development 129

available to one or more JSP pages, it has an attribute named var that lets you specify the name
of that scoped variable. Listing 3-34 illustrates the action, available in the core tag library of
JSTL, to set the value of a scoped variable.


Listing 3-34. Using



Listing 3-34 sets a variable called name to the value hello and allows that variable to be visible in
session scope. If the value for scope is not specified, the default scope is page scope. In the section
that follows, you will learn all the actions in different functional areas provided in the core tag library.


The Core Tag Library

Table 3-5 describes the core actions in the core tag library.


Table 3-5. Core Actions in the Core Tag Library


Action Description

<c:catch> Catches exceptions thrown in the action’s body
<c:choose> Chooses one of many code fragments
<c:forEach> Iterates over a collection of objects or iterates a fixed number of times
<c:forTokens> Iterates over tokens in a string
<c:if> Conditionally performs some functionality
<c:import> Imports a URL
<c:otherwise> Specifies default functionality in a <c:choose> action
<c:out> Sends output to the current JspWriter
<c:param> Specifies a URL parameter for <c:import> or <c:url>
<c:redirect> Redirects a response to a specified URL
<c:remove> Removes a scoped variable
<c:set> Creates a scoped variable
<c:url> Creates a URL, with URL rewriting as appropriate
<c:when> Specifies one of several conditions in a <c:choose> action

The JSTL core library can be divided into four distinct functional areas, as described in Table 3-6.

Free download pdf