Learn Java for Web Development

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

The action can handle errors from any action by nesting those actions within .
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 .


Listing 3-44. Using




<% int i = 1/0;%>


Exception : ${exception}


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

Table 3-12. Attributes


Name Type Description

var String Name of the exported scoped variable for the exception
thrown from a nested action.

The Action


The action is used for conditional processing and evaluates an expression, displaying its
body content only if the expression evaluates to true.

Free download pdf