gpt4 book ai didi

java - Struts 2 迭代器标签

转载 作者:行者123 更新时间:2023-12-01 12:35:21 24 4
gpt4 key购买 nike

我有一个 Java Bean 集合,我想使用迭代器标记在 JSP 中对其进行迭代。

列表按此标签排序的默认顺序是什么?因为它不按照 Bean 在列表中添加的顺序进行迭代。

这是struts Action 类代码:

public String getUsersTraceJSP() {

try {

Map session = ActionContext.getContext().getSession();
Properties properties = new Properties();
InitialContext ic = new InitialContext(properties);
PartnerSessionBeanRemote bIRemote = (PartnerSessionBeanRemote) ic.lookup(PartnerSessionBeanRemote.class.getName());

UserLoginTraceForm ultf = bIRemote.getUserLoginTrace(Long.parseLong(userId));

for (UserLoginTraceForm uu : ultf.getUltList()) {
System.out.println("ULT ID | " + uu.getUltId());
}

session.put("ULTF", ultf);

} catch (Exception e) {
e.printStackTrace();
Logger.printError("ERROR", "AppFilesAction.getUsersTraceJSP() ", e);
}

return "success";
}

System.out.println("ULT ID | "+ uu.getUltId()) 给出以下输出:

INFO:   ULT ID | 91
INFO: ULT ID | 9
INFO: ULT ID | 86
INFO: ULT ID | 84
INFO: ULT ID | 83
INFO: ULT ID | 82
INFO: ULT ID | 81
INFO: ULT ID | 8
INFO: ULT ID | 74
INFO: ULT ID | 73
INFO: ULT ID | 72
INFO: ULT ID | 71
INFO: ULT ID | 70
INFO: ULT ID | 7
INFO: ULT ID | 69
INFO: ULT ID | 68
INFO: ULT ID | 67
INFO: ULT ID | 66
INFO: ULT ID | 65
INFO: ULT ID | 64
INFO: ULT ID | 63
INFO: ULT ID | 62
INFO: ULT ID | 61
INFO: ULT ID | 6
INFO: ULT ID | 5
INFO: ULT ID | 49
INFO: ULT ID | 48
INFO: ULT ID | 47
INFO: ULT ID | 46
INFO: ULT ID | 45
INFO: ULT ID | 44
INFO: ULT ID | 43
INFO: ULT ID | 42
INFO: ULT ID | 41
INFO: ULT ID | 40
INFO: ULT ID | 4
INFO: ULT ID | 39
INFO: ULT ID | 38
INFO: ULT ID | 37
INFO: ULT ID | 36
INFO: ULT ID | 35
INFO: ULT ID | 34
INFO: ULT ID | 33
INFO: ULT ID | 32
INFO: ULT ID | 31
INFO: ULT ID | 30

JSP 是:

输出是这样的: List View on JSP

<div class="row" style="height:92.5%;padding-left: 1%;padding-right: 1%;overflow: auto">
<div id="tableDiv" >

<table id="formList" class="display" cellspacing="0" width="100%">
<thead style="background-color: #BDC6E7">
<tr>
<th>ultId>
<th>Login Time</th>
<th>IP Address</th>

</tr>
</thead>
<tbody>


<s:iterator value="#session.ULTF.ultList">
<tr>

<td><s:property value="ultId"/></td>
<td><s:property value="loginTime"/></td>
<td><s:property value="ipAddress"/></td>

</tr>
</s:iterator>
</tbody>
</table>



</div>

</div>

最佳答案

如果您需要一个保留其元素插入顺序的Collection,请使用本质上有序的List,或者以Linked 开头的类,如 LinkedHashSetLinkedHashMap 等...这正是它们与其他实现的不同之处。了解更多 this answer .

关于java - Struts 2 迭代器标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25645082/

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