日期:2014-05-18  浏览次数:20696 次

c:forEach循环的问题
<sql:query   var= "q1 "   sql= "select   *   FROM   answer_record   where   result= 'right '   and   user_id= '${user_id} '   and   unit_id   = '${unit_id} '   and   article_id= '${article_id} '     "   dataSource= "${ds} "/>
<c:forEach   var= "f "   items= "${q1.rows} ">
    <%--在这个循环里question_id是1,3--%>
    <c:set   var= "question_id "   value= "${f.question_id} "/>
    <c:set   var= "record "   value= "${f.record} "/>
</c:forEach>
……………
<sql:query   var= "q "   sql= "select   *   from   question_answer   where   article_id   = '${article_id} 'and   unit_id   = '${unit_id} '   order   by   question_id "   dataSource= "${ds} "/>
<%--另一个forEach--%>
<c:forEach   var= "f "   items= "${q.rows} ">
    <%--在这个循环里question_id1是1,2,3,4--%>
    <c:set   var= "question_id1 "   value= "${f.question_id} "/>
    <%--我想问在这里怎么得到question_id是1,3??--%>
    <c:if   test= "${question_id==question_id1} ">
        <%--   question_id的1等于question_id1的1   或   question_id的3等于question_id1的3   的处理--%>
        ………………  
      </c:if>
    <c:if   test= "${question_id!=question_id1} ">
        <%--   这里出示question_id1的2,4内容的处理   --%>
        ………………  
      </c:if>
</c:forEach>
怎样才能实现这个功能呢?

------解决方案--------------------
给你一个思路.
<c:set var= "count " value= "100 "/>
<c:forEach var= "temp " begin= "1 " step= "1 " end= "${count} ">
<c:if test= "${temp%2 ne 0} ">
<c:out value= "${temp} "/>
</c:if>
</c:forEach>