ChatGPT解决这个技术问题 Extra ChatGPT

How to loop over something a specified number of times in JSTL?

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?

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


B
BalusC

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.

Here's a kickoff example:

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

@jon20usa Check out the JSTL Tag Reference to learn the finer details about these tags.
@elekwent: The blueish parts in my answer are links already :)
Ahh, so they are. Oops, I meant to add that comment to the original question.
@elekwent: ah OK, no problem. You can also find more info and links in our JSTL tag wiki page. Hover the [jstl] tag below the question until a popbox shows and click the info link there.