Maven Dependency:

<dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>jstl</artifactId>
           <version>1.2</version>
 </dependency>

Controller:

@RequestMapping(value = "jstlForEach", method = RequestMethod.GET)
   public String jstlForEach(ModelMap model) {
       List<Employee> employees = new ArrayList<>();

       employees.add(new Employee(1, "Subhash Lamba"));
       employees.add(new Employee(2, "Mahesh Lamba"));
       model.put("employees",employees);
       return "jstlForEach";
   }

JSP Page:

<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<table>
    <tr>
        <th>Employee ID</td>
        <th>Employee Name</tr>
    </tr>
    <c:forEach items="${employees}" var="employee">
        <tr>
            <td><c:out value="${employee.employeeId}"/></td>
            <td><c:out value="${employee.employeeName}"/></td>
        </tr>
    </c:forEach>
</table>

Output:

jstl for each loop

jstl for each loop

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *