in a JSP I should print the values of an array list in the “li” html tags. The problem is that I should print in one cycle two values. This is the example in html:
<ul class="myProfileTeamNameList">
<li><p class="first">- Team_Name_1</p><p>- Team_Name_2</p></li>
</ul>
I have implemented this but I can only print the first value. This is my code:
<ul class="myProfileTeamNameList">
<c:forEach var="team" items="${teams}">
<li><p class="first">- ${team.name}</p> <p>- ${team.name}</p></li>
</c:forEach>
</ul>
instead in the second
html tag I should write the SUCCESSIVE array list value. Something like: ${team.name} + 1
Can someone help me? Thanks a lot.
Ideally, you should not use a list. You should use a
Map, and loop through its entries to get the key and value.But if you really need to use the list,
<c:forEach>allows you to write a index-based loop. Instead ofitems, specifystep=2,begin,endandvarStatusand then refer to${items[varStatus.index]}(and.index+1respectively). E.g.