JSTL forEach List Iteration
JSTL forEach List Iteration Example explains about How to Iterating a List using JSTL Taglib
List is an ordered pair of objects, It may contains duplicates, but it keeps correct the insertion order
Consider a JSP page, which contains a ArrayList with lot of items inside it and we need to iterate and display the items inside that particular ArrayList
You can access an element from this collection using ${item} using a variable var="item"
This JSTL 'c:forEach is available for all the List / Collection implementations in java
Following example shows How to iterate a List using JSTL c:forEach
Required Libraries
Project Structure
JSTL List Example
// JSTL c:forEach Example <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ page import="java.util.ArrayList"%> <% ArrayList<String> numList = new ArrayList<String>(); numList.add("1"); numList.add("2"); numList.add("3"); request.setAttribute("numList", numList); %> <html> <body> <c:forEach items="${numList}" var="item"> ${item} </c:forEach> </body> </html>