Name

<x:if>

Synopsis

The <x:if> action evaluates its body only if the specified XPath expression evaluates to true. Alternatively, the evaluation result can be saved as a scoped Boolean variable.

Syntax 1: Without a body

<x:if select="booleanXPathExpression" 
  var="var" [scope="page|request|session|application"]/>

Syntax 1: With a body

<x:if select="booleanXPathExpression">
  JSP elements
</x:if>

Attributes

Attribute name

Java type

Dynamic value accepted

Description

select
String

No

The XPath expression to evaluate.

var
String

No

The variable name. The type is Boolean.

scope
String

No

The variable scope.

Example

<x:if select="category[. = 'General']">
  <b>General</b>
</x:if>

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.