how to code foreach involving 3 lists in jstl?

余生颓废 提交于 2019-12-25 16:58:17

问题


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..


回答1:


Something like this

<c:forEach items="${auctionDOList}" var="list" varStatus="counter">
    ${list.auctionId} ${depotList[counter.count].depotName} ${userAuctionRelDolist2[counter.count].auctionId}
</c:forEach>



回答2:


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




回答3:


you will need forEach to do this. Refer this links

http://www.tutorialspoint.com/jsp/jstl_core_foreach_tag.htm

http://www.crazysquirrel.com/computing/java/jsp/jstl-forEach.jspx

being more specific you'll need nested forEach

http://www.coderanch.com/t/288775/JSP/java/jstl-nested-foreach

http://www.roseindia.net/jsp/simple-jsp-example/NestedForEach.shtml



来源:https://stackoverflow.com/questions/21190153/how-to-code-foreach-involving-3-lists-in-jstl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!