JSP mod operator does not work

I'm trying to do it, but it will still be part

<c:forEach items="${records}" var="field" varStatus="counter"> <c:choose> <c:when test="${counter.count mod 2 == 0}"> <div class="classEven"> </c:when> <c:otherwise> <div class="classOdd"> </c:otherwise> </c:choose> sample text here </div> </c:forEach> 

What happened to this?

+6
source share
3 answers

You can also use ${counter.count % 2 == 0}

+19
source
 test = ${counter.index mod 2 == 0} 
+1
source

Separated jstl from html + plus no math for you, artsy types

 <c:set var="row" value="Even" /> <c:forEach items="${records}" var="field" varStatus="counter"> <c:choose> <c:when test="${row eq 'Odd'}"> <c:set var="row" value="Even" /> </c:when> <c:otherwise> <c:set var="row" value="Odd" /> </c:otherwise> </c:choose> <div class="class${row}"> sample text here </div> </c:forEach> 
-2
source

Source: https://habr.com/ru/post/907562/


All Articles