我有一个arraylist,它由名为“历史”的定制对象组成。当我单击一个链接(代码示例顶部名为“deposit1”)时,我会按正确的顺序显示列表。
但是,我希望在用户单击表中的链接“deposit2”时能够反转列表,该链接仅在用户单击第一个链接“deposit1”后显示。
现在什么都没有发生,但我可以系统。输出。打印成功的secound链接点击。
有什么办法吗?
请注意,为了更好地概述,对代码示例进行了裁剪。
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>
2条答案
按热度按时间pkmbmrz71#
更改第一个
if-sortDep1
收件人:当其中一个有效时,总是输入代码的这一部分。
3wabscal2#
你可以通过
2
href标记中的参数Dept1
&Dept2
以便sortDep1
不为空,它将进入内部if-statement
根据url中的值,可以反转列表。即: