ul-li html标记中的JSTL打印数组列表值.正确的算法. [英] JSTL print array list values in ul - li html tag. Right Algorithm.

查看:90
本文介绍了ul-li html标记中的JSTL打印数组列表值.正确的算法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSP中,我应该在"li" html标记中打印数组列表的值.问题是我应该在一个周期中打印两个值.这是html中的示例:

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>

而不是在第二个

html标记中,我应该写入SUCCESSIVE数组列表值.类似于:$ {team.name} + 1

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.

推荐答案

理想情况下,您不应使用列表.您应该使用 Map ,并循环浏览其条目以获取键和值.

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 of items, specify step=2, begin, end and varStatus and then refer to ${items[varStatus.index]} (and .index+1 respectively). E.g.

<c:forEach step="2" being="0" end="${fn:length(array)}" varStatus="status">
    ${items[varStatus.index]} - ${items[varStatus.index+1]}
</c:forEach>

这篇关于ul-li html标记中的JSTL打印数组列表值.正确的算法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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