gpt4 book ai didi

java - 使用 foreach 在单行/表中显示多个列表

转载 作者:太空宇宙 更新时间:2023-11-04 07:06:53 26 4
gpt4 key购买 nike

我是 jSTL 新手..我正在尝试在表中的 1 行中显示 4 个列表..我跟着这个“ how to code foreach involving 3 lists in jstl?

 <c:forEach items="${actionList}" var="action" varStatus="counter"> 
<tr>
<td><c:out value= "${action.cut}"/></td>
<td><c:out value= "${dustList[counter.count].dust}"/></td>
<td><c:out value= "${myList[counter.count].name}"/></td>
<td><c:out value= "${megaList[counter.count].megaprice}"/></td>
</tr>

结果是我得到了第一列alrt..但是其余的列没有显示任何内容..servlet 获取了值alrt..

 request.setAttribute("actionList", actionList);
request.setAttribute("dustList", dustList);
request.setAttribute("myList", myList);
request.setAttribute("megaList", megaList);

传递也正确发生..调用也正确..那么我哪里出错了?为什么只显示一个列表?控制台没有显示错误..

最佳答案

您要使用的是 varStatus 的 index 而不是 count

<td><c:out value= "${dustList[counter.index].dust}"/></td>
<td><c:out value= "${myList[counter.index].name}"/></td>

注意

${status.index} = 基于 0 的索引

${status.count} = 1 个基于索引

我还假设有诸如 getMegaprice()megaprice 之类的方法是公共(public)的。

关于java - 使用 foreach 在单行/表中显示多个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com