Name

<c:forTokens>

Synopsis

The <c:forTokens> action evaluates its body once for each token in a String, delimited by one of the specified delimiter characters. The current token and the iteration status can be exposed to action elements in the body through nested variables.

Syntax

<c:forTokens items="stringOfTokens" delims="delimiters"
  [var="var"] [varStatus="varStatus"]
  [begin="startIndex"] [end="stopIndex"] [step="increment"]>
  JSP elements
</c:forTokens>

Attributes

Attributename

Java type

Dynamic valueaccepted

Description

items
String

Yes

The tokens to iterate over.

delims
String

Yes

The list of delimiter characters.

var
String

No

The name of the nested variable holding the current element.

varStatus
String

No

The name of the nested variable holding the LoopTagStatus object.

begin
int

Yes

The 0-based start index. Default is 0.

end
int

Yes

The 0-based stop index (inclusive). The default is the last token.

step
int

Yes

The index-increment value for each iteration. Default is 1.

Example

<%-- Iterate over tokens separated by vertical bars --%>
<c:forTokens items="${tokens}" delims="|" var="current">
  <c:out value="${current }" />
</c:forTokens>

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.