I do not have much experience with jsp. In java I can do, but it is not good to open a block <% %>
Asked
Active
Viewed 4,955 times
1
-
2Why is it not good to open a block? Show us how you'd do it in java... – ControlAltDel Jul 05 '12 at 18:06
-
You can write code in a JSP. And you can call a method in a class to do your loop if you want to avoid cluttering your JSP. – Denys Séguret Jul 05 '12 at 18:07
-
1@ControlAltDel, As per jsp specification, scriptlets need to be avoided if possible. Read this answer from BalusC http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files?lq=1 – kosa Jul 05 '12 at 18:09
-
@ControlAltDel: http://stackoverflow.com/questions/1835683/how-to-loop-through-a-hashmap-in-jsp – Falci Jul 05 '12 at 18:15
1 Answers
8
You can use JSTL foreach to iterate over the HashMap.
<c:forEach var="type" items="${yourMap}">
Key is ${type.key}
Value is ${type.value}
</c:forEach>
NOTE: If you are using Tomcat, you need to explicitly copy JSTL lib to classpath. With other servers I know of default comes with JSTL.

kosa
- 65,990
- 13
- 130
- 167