如何在JSTL中循环指定次数的内容? [英] How to loop over something a specified number of times in JSTL?

查看:245
本文介绍了如何在JSTL中循环指定次数的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在JSTL中进行while循环.我似乎找不到如何遍历指定次数的东西.有什么想法可以实现这一目标吗?

I need a while loop within JSTL. I cannot seem to find how to loop over something a specified number of times. Any ideas how I can accomplish this?

我认为我可以使用forEach,但是我并不真正想遍历一个集合.

I am thinking I could use a forEach but I do not really care to loop over a collection.

推荐答案

LoopTagStatus对象在循环标记作用域中,该作用域又具有getIndex()之类的几种方法.

The <c:forEach> tag is definitely suitable for this. It has begin and end attributes where you can specify the, well, begin and end. It has a varStatus attribute which puts a LoopTagStatus object in the loop tag scope which in turn has several methods like getIndex() and on.

这是一个开球示例:

<c:forEach begin="0" end="10" varStatus="loop">
    Index: ${loop.index}<br/>
</c:forEach>

这篇关于如何在JSTL中循环指定次数的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆