【发布时间】:2020-06-15 18:45:37
【问题描述】:
我正在尝试在 JSP 中显示 ArrayList。我必须要遍历 ArrayLists 并在同一个 JSP 表中显示数据。对于第一个 Arralist(历史),这很好用,但是当我到达第二个时,它会显示每行中的所有 ArrayList,而不是循环中的当前索引:
<table id="test" class="table text">
<tr>
<th>Result</th>
<th>Deposit</th>
<th>Bet</th>
<th>Return +/-</th>
<th>Current balance</th>
<th>Date</th>
</tr>
<%
for (history his : history) {
%>
<tr class="listing">
<td><%=his.getRes()%></td>
<td><%=resultTwoDecimalsDeposit%></td>
<td><%=his.getOdds()%></td>
<td><%=his.getDate() %> </td>
<td style="color:#00cc00;"> + <%=resultTwoDecimalsRet%> </td>
到这里为止一切都很好。它不显示循环中的当前索引,而是显示每个 tr 中的所有 ArrayList
<% for (int i = 0; i < list1.size(); i++) {
%>
<td><%=list1.get(i) %></td>
<% } %>
<%}}}%>
</tr>
</table>
【问题讨论】:
-
您是否在
for之前添加了<tr>?请edit您的问题并包括一个真实的minimal reproducible example,而不仅仅是代码部分。 -
我没有放任何其他
然后在示例中显示 -> 我总共有 2 个 。 如果你只有一个<tr>和一个</tr>,那么这就是一行输出。
标签: java loops jsp for-loop arraylist