在 JSP 中,我应该在“li”html 标记中打印数组列表的值。问题是我应该在一个周期内打印两个值。这是 html 中的示例:
<ul class="myProfileTeamNameList">
<li><p class="first">- Team_Name_1</p><p>- Team_Name_2</p></li>
</ul>
我已经实现了这个,但我只能打印第一个值。这是我的代码:
<ul class="myProfileTeamNameList">
<c:forEach var="team" items="${teams}">
<li><p class="first">- ${team.name}</p> <p>- ${team.name}</p></li>
</c:forEach>
</ul>
而不是在第二个
html 标记中,我应该编写 SUCCESSIVE 数组列表值。类似于:${team.name} + 1
有人可以帮助我吗?非常感谢。
最佳答案
理想情况下,您不应使用列表。您应该使用 Map
,和loop through its entries获取键和值。
但是如果您确实需要使用该列表, <c:forEach>
允许您编写基于索引的循环。而不是items
,指定step=2
, begin
, end
和varStatus
然后引用${items[varStatus.index]}
(和 .index+1
分别)。例如
<c:forEach step="2" being="0" end="${fn:length(array)}" varStatus="status">
${items[varStatus.index]} - ${items[varStatus.index+1]}
</c:forEach>
关于java - JSTL 在 ul - li html 标记中打印数组列表值。正确的算法。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6873459/