0

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.

Vidya
  • 196
  • 14
HighNESS
  • 57
  • 1
  • 2
  • 8
  • possible duplicate http://stackoverflow.com/questions/18825950/how-to-get-a-index-value-from-foreach-loop-in-jstl – Ruelos Joel Dec 18 '15 at 09:18
  • Possible duplicate of [How to get a index value from foreach loop in jstl](http://stackoverflow.com/questions/18825950/how-to-get-a-index-value-from-foreach-loop-in-jstl) – shashankg77 May 19 '17 at 12:20

1 Answers1

2

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.

phortx
  • 849
  • 5
  • 21
  • well, I want to store the index in a variable which can be accessed in javascript within the jsp,i need to store it in string or int, The problem being I don't know how to use jstl tags with javascript. – HighNESS Dec 18 '15 at 20:38
  • You have to understand that JSP is executed on the serverside. Just write a JavaScript function like you would do in plain HTML: `` ... you can also replace `someVariable` with an EL Expression to output the index: `` which will result in `` for example. – phortx Dec 18 '15 at 23:32