Java Reference
In-Depth Information
The syntax for the
<c:choose>
action is as follows:
<c:choose>
body content (<c:when> and <c:otherwise>)
</c:choose>
As you can see, the
<c:choose>
action has two possible nested actions that form its body:
<c:when>
and
<c:otherwise>
. The syntax for each is as follows:
<c:when test="testCondition">
body
</c:when>
<c:otherwise>
body
</c:otherwise>
Table
3-15
illustrates the attributes of the
<c:when>
action.
Table 3-15.
<c:when> Attributes
Name
Type
Description
test
Boolean
The test condition that determines whether the body content should be processed
Listing 3-46 illustrates a simple usage of
<c:choose>
.
Listing 3-46. Using <c:choose>
<body>
<c:set var="number" value="10"/>
<c:choose>
<c:when test="${number < 10}">
Number is less than 10.
</c:when>
<c:when test="${number > 10}">
Number is greater than 10.
</c:when>
<c:otherwise>
Number is equal to 10
</c:otherwise>
</c:choose>
</body>
Here's the output:
Number is equal to 10