3

我是新手,目前正在编辑朋友的现有代码,我只是想知道是否有一种简单的方法可以在 JSTL/JSF 中为类似于此的 Java 代码执行嵌套 for 循环:

blocks=0;
for(vElement=0; blocks<19; vElement++){
   for(hElement=0; exit<1; hElement++){
      System.out.println(blocks);
      if(blocks!=18){
          blocks++;
      } else{
          exit = 1;
      }
   }
   System.out.println("\n");
}

输出将是这样的:

0   1   2   3   4   5   6
7   8   9   10  11  12  13
14  15  16  17  18

我在这里看到的一切都与 Backing Bean 有关(我真的不需要这个)。有什么建议么?

4

1 回答 1

3
<c:forEach var="i" begin="0" end="2">
  <c:forEach var="j" begin="0" end="6">
     <c:if test="${(i*7 + j) <=18}">
                       <c:out value="${(i*7 + j)}" />
     </c:if>
  </c:forEach>
  <br />
</c:forEach>

注:未测试

克隆BalusC 的请求我也添加了新请求

另见

于 2012-05-22T07:57:29.137 回答