Name

<c:when>

Synopsis

The <c:when> action represents one of the mutually exclusive alternatives within a <c:choose> block. It evaluates its body only if it’s the first <c:when> action in the block with a test expression that evaluates to true.

Syntax

<c:when test="booleanExpression">
  JSP elements
</c:when>

Attributes

Attribute name

Java type

Dynamic value accepted

Description

test
boolean

Yes

The test expression

Example

<c:choose>
  <c:when test="${product.onSale}">
    <c:out value="${product.salesPrice}" /> On sale!
  </c:when>
  <c:otherwise>
    <c:out value="${product.price}" />
  </c:otherwise>
</c:choose>

Get JavaServer Pages, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.