jsp - 如何使用strut标签在JSP中迭代hashmap

标签 jsp struts hashmap

我可以打印 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/

相关文章:

java - 对 HashMap 进行排序,定义限制并转换为 ArrayList

javascript - 如何在javascript中使用scriptlet

java - 错误: No tag "iterator" defined in tag library imported with prefix "logic"

java - 如何向 struts web 应用程序添加印地语语言支持

java - 如何从 Ajax 或 JavaScript 调用 Struts1 Action?

java - 无法将对象转换为 HashMap

java - pac4j-saml 客户端未向 IDP 发送请求

java - 是否可以在 WebSphere Application Server 上自动运行 Java 应用程序?

javascript - 在javascript中设置多值参数

c++ - Protocol Buffer 可以序列化 hash_multimap 吗?