Java 使用<;c:forEach>;使用HashMap
我有一个java类,它将servlet属性设置为HashMap对象:Java 使用<;c:forEach>;使用HashMap,java,jsp,jstl,Java,Jsp,Jstl,我有一个java类,它将servlet属性设置为HashMap对象: request.setAttribute("types", da.getSecurityTypes()); 其中,request是一个HttpServletRequest对象,而da.getSecurityTypes()返回一个HashMap对象 有没有办法使用c:foreach或其他一些JSTL标记遍历HashMap集合 我在想: <c:forEach var="type" items="${types}">
request.setAttribute("types", da.getSecurityTypes());
其中,request
是一个HttpServletRequest对象,而da.getSecurityTypes()
返回一个HashMap对象
有没有办法使用c:foreach或其他一些JSTL标记遍历HashMap集合
我在想:
<c:forEach var="type" items="${types}">
...
</c:forEach>
...
或者,如果不能做到这一点,人们将如何制作自定义标记来处理这一点
在我的JSP页面中使用Java代码是我最后的选择,我想知道使用JSTL是否可行
谢谢,
Jonas。它可以工作,你可以在循环中使用
type.key
和type.value
。是的,这是完全可以接受的
使用
在映射上迭代时,迭代中的每个项都是映射项的实例。举个例子:
<c:forEach var="type" items="${types}">
Key is ${type.key}
Value is ${type.value}
</c:forEach>
键为${type.Key}
值为${type.Value}
我发现了一件困难的事情,那就是不能在第二个
循环中重用同一个变量。您需要提供一个不同的名称。