我可以打印 HashMap 的键值,如下所示
<%
HashMap<String,String> students = new HashMap<String,String>();
students.put("1","Amit");
students.put("2","Amit");
students.put("3","Anil");
students.put("4","Amit");
session.setAttribute( "students", students );
%>
<bean:write name="students" property="1" />
<bean:write name="students" property="3" />
如何迭代打印 key 及其值?
最佳答案
嗯!!谷歌搜索后我在任何地方都找不到这个答案。但不知何故,我在没有使用 EL 或 scriptlet 的情况下做到了这一点。
<logic:iterate name="students" id="nameObj" scope="session">
<bean:write name="nameObj" property="key"/>
<bean:write name="nameObj" property="value"/>
</logic:iterate>
关于jsp - 如何使用strut标签在JSP中迭代hashmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8653951/