136 CHAPTER 3: Best Practices in Java EE Web Development
Here’s the syntax without body content:
<c:if test="testCondition"
var="varName" [scope="{page|request|session|application}"]/>
Here’s the syntax with body content:
<c:if test="testCondition"
[var="varName"] [scope="{page|request|session|application}"]>
... body content...
Using the test attribute, a Boolean EL expression is evaluated. If the test condition evaluates to
true, only then the body of the action is executed. The Boolean result of the expression evaluation is
exported to a scoped variable using the var attribute. The default scope of the var is page, but using
the scope attribute, the scope could be set to any of the JSP scopes.
Table 3-14 illustrates the attributes of the
Table 3-14.
Name Type Description
test Boolean The test condition that determines whether the body content should be processed.
var String The name of the exported scoped variable for the resulting value of the test
condition.
scope String The scope for var.
Listing 3-45 illustrates using
Listing 3-45. Using
Here’s the output:
number is less than 10
The
The
switch statement and lets you choose between a number of alternatives, using
of case statements and
with a default clause.