How to Iterate HashMap using JSTL

This article shows how to iterate through a map using the tag <c:forEach> of the JSP standard tag library (JSTL).

1. Java File

Map<String, Integer> employeeMap = new HashMap<String, Integer>();
employeeMap.put("11-20", 12);
employeeMap.put("21-30", 50);
employeeMap.put("31-40", 3);
request.setAttribute("employeeMap", employeeMap);

2. JSP File

<c:forEach var="employee" items="${employeeMap}">
    Age Group: ${employee.key}  - Count: ${employee.value}

No comments yet.

Leave a Reply