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

JspLoopsJstl

Jsp Problem Overview


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.

Jsp Solutions


Solution 1 - Jsp

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonathan HultView Question on Stackoverflow
Solution 1 - JspBalusCView Answer on Stackoverflow