Java Reference
In-Depth Information
Table 3-12.
<c:catch> Attributes
Name
Type
Description
var
String
Name of the exported scoped variable for the exception
thrown from a nested action.
The
<c:catch>
action can handle errors from any action by nesting those actions within
<c:catch>
.
When an exception is thrown, it is stored in a page-scoped variable that is identified by the
var
attribute of the tag. Listing 3-44 illustrates the usage of
<c:catch>
.
Listing 3-44. Using <c:catch>
<body>
<c:catch var = "exception">
<% int i = 1/0;%>
</c:catch>
<c:if test = "${exception != null}">
<span> Exception : ${exception}</span>
</c:if>
</body>
Here's the output:
Exception : java.lang.ArithmeticException: / by zero
Conditionals
The conditional tags provided by the JSTL core tag library provide an alternative to using scriptlets
for generating dynamic content based on conditions. Table
3-13
describes the actions in this
functional area.
Table 3-13.
Conditional Actions in the Core Tag Library
Action
Description
<c:if>
Evaluates its body content if the expression specified with the
test
attribute is
true
<c:choose>
Provides the context for mutually exclusive conditional execution
<c:when>
Represents an alternative within a
<c:choose>
action
<c:otherwise>
Represents the last alternative within a
<c:choose>
action
The <c:if>Action
The
<c:if>
action is used for conditional processing and evaluates an expression, displaying its
body content only if the expression evaluates to
true
.