HighNESS
HighNESS

Reputation: 67

How to get the index of forEach loop in integer

I want to get the index of forEach loop in integer, I can get it in terms of string i.e

<c:forEach var="row" items="${result.rows}" varStatus="loop">
    <c:out value="${loop.index}"/>
</c:forEach>

I want to store the value of index in an integer variable, jsp.

Upvotes: 0

Views: 6434

Answers (1)

phortx
phortx

Reputation: 909

Just store it in a variable, it will actually be an integer:

<c:set var="index" value="${loop.index}" />
<c:set var="index" value="${index + 1}" />
<c:out value="${index}"/>

Should produce 1 2 3 and so on.

Upvotes: 2

Related Questions