我有一堆Java Bean,我想使用迭代器标记在JSP中进行迭代。
此标记对列表进行排序的默认顺序是什么? 因为它不按照列表中添加bean的顺序进行迭代。
这是struts动作类代码:
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是:
,输出为:
<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>
答案 0 :(得分:1)
如果您需要保留其元素的插入顺序的Collection
,请使用内向排序的List
或以Linked
开头的类,例如{{1} }},LinkedHashSet
等... 完全是什么使它们与其他实现不同。详细了解this answer。