2012-02-03 90 views
6

我想这一点,但它要else部分总是JSP MOD操作不工作

<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> 

这有什么错呢?

+2

你试过用'$ {(counter.count模2)== 0}'? – 2012-02-03 12:05:46

+0

是的,它的工作现在..谢谢JB – user965884 2012-02-03 12:16:20

回答

19

你也可以使用${counter.count % 2 == 0}

-2

分居JSTL从HTML +加上没有数学你显得扑朔迷离类型

<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> 
1
test = ${counter.index mod 2 == 0}