如何在jstl中编写涉及3个列表的foreach? [英] how to code foreach involving 3 lists in jstl?
问题描述
这是从这个问题的后续。
如何在jsp中显示3个arraylist?
我在java中有下面的代码..我需要一个相当于jsp的代码。 jstl代码首选..
int i = 0; (AuctionDo list:auctionDOList)
{
System.out.println(+ list.getAuctionId()++ depotDolist.get(i).getDepotName()+ + userAuctionRelDolist2.get(i).getAuctionId());
i ++;
}
这三个列表是在jsp中接收的..谢谢..
1非常重要的事情,我想显示在一个表中的列表在一个表中..所以多个foreach是没有选择,并尝试合并名单..几乎没有工作..
< c:forEach items = $ {list}var =firstListElementvarStatus =counter>
<% - 列表的拍卖ID - %>
$ {list.auctionId}
<% - 基于迭代计数的depotList项目的仓库名称 - %>
$ {depotList [counter.count] .depotName}
<% - 基于迭代计数的userAuctionRelDolist2项目的拍卖ID - %>
$ {userAuctionRelDolist2 [counter.count] .auctionId}
< / c:forEach>
计数器持续跟踪迭代计数变量。
注意:由于 forEach
循环取决于第一个列表的大小。当 depotList
或 userAuctionrelDolist
的大小大于第一个列表的大小时,这将无法正常工作。 p>
this is a follow on from this question.. how to display 3 arraylist's in a jsp?
well i have this following code in java.. i need an equivalent one for use in jsp.. jstl codes preferred..
int i=0;
for(AuctionDo list : auctionDOList)
{
System.out.println(" "+ list.getAuctionId()+ " " + depotDolist.get(i).getDepotName() + " " + userAuctionRelDolist2.get(i).getAuctionId() );
i++;
}
the three lists are received in jsp.. thankyou.. 1 very important thing i want to display the lists in one row in a table.. so multiple foreach is out of option and tried merging the lists.. pretty much didnt work..
You have to do like this
<c:forEach items="${list}" var="firstListElement" varStatus="counter">
<%-- auction id of list --%>
${list.auctionId}
<%-- depot name of depotList item based on iteration count --%>
${depotList[counter.count].depotName}
<%-- auctionId of userAuctionRelDolist2 item based on iteration count --%>
${userAuctionRelDolist2[counter.count].auctionId}
</c:forEach>
counter keeps tracking of the iteration count variable.
Note: Since the forEach
loop depends on the size of the first list. This will not work correctly when the size of the depotList
or userAuctionrelDolist
is greater than the size of the first list
这篇关于如何在jstl中编写涉及3个列表的foreach?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!