Name

<ora:ifContains>

Synopsis

The <ora:ifContains> action tests if a string contains a substring. If so, its body is evaluated, or the Boolean test result is saved in the specified variable.

Syntax 1: Conditionally evaluate the body

<ora:ifContains value="testValue" substring="substring">
  Evaluated if the testValue contains the substring
</ora:ifContains>

Syntax 2: Saving the test result

<ora:ifContains value="testValue" substring="substring"
  var="var" [scope="page|request|session|application"] />

Attributes

Attributename

Java type

Dynamic valueaccepted

Description

value
String

EL expression

The main string value to test if it contains the substring

substring
String

EL expression

The substring

var
String

No

The name of the variable

scope
String

No

Scope for the variable

Example

<%-- 
  Evaluate the body if the User-Agent contains "MSIE"
--%>
<ora:ifContains value="${header['User-Agent']" substring="MSIE">
  You're using Internet Explorer
</ora:ifContains>
  
<%-- 
  Save true in the isIE variable if the User-Agent contains "MSIE"
--%>
<ora:ifContains value="${header['User-Agent']" substring="MSIE"
  var="isIE" />

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.