【发布时间】:2020-12-09 12:22:25
【问题描述】:
我有一个 ArrayList,它由称为“历史”的定制对象组成。当我点击一个链接时,我的代码示例顶部名为“Deposit1”的链接,我以正确的顺序显示列表。
但是,当用户单击表内的链接“Deposit2”时,我希望能够反转列表,该链接仅在用户单击第一个链接“Deposit1”后显示。
现在什么都没有发生,但我可以在第二个链接点击时成功 system.out.print。
有没有办法做到这一点?
请注意,为了更好地概述,代码示例已被修剪。
ArrayList <history> history = historyDAO.getHistory(x, y);
<li>
<a href="history.jsp?Dep1=valueOfDep">Deposit1</a>
</li>
String sortDep1 = request.getParameter("Dep1");
String sortDep2 = request.getParameter("Dep2");
if (sortDep1 != null) {
<table class="table text">
<tr>
<th>Result</th>
<th>Sport</th>
<th>Deposit2<a href="history.jsp?Dep2=valueOfDep">Deposit2</a></th>
</tr>
if (sortDep2 != null) {
Collections.reverse(history);
}
for (int i = 0; i < history.size() && i < list1.size(); i++) {
<tr>
<td><%=history.get(i).getRes()%></td>
<td><%=history.get(i).getSport() %></td>
<td><%=history.get(i).getDeposit()%></td>
</tr>
<%}}%>
</tr>
</table>
【问题讨论】:
-
if-sortDep2 嵌套在 if-sortDep1 中,因此永远不会被调用为设置 Dep1 或 Dep2 的链接。
-
是的,正是我的问题。如果我将 if-sortDep2 嵌套在外面,它将“重置”我的页面,并且不显示来自 if-sortDep1 的数据。所以,否则我将不得不做很多冗余。
标签: java jsp arraylist reverse