JSP for Each

The JSP for Each helps you to iterate over the data in JSP and print the corresponding values on the browser.

JSP for Each

JSP for Each

        

The JSP for Each helps you to iterate over the data in JSP and print the corresponding values on the browser.

Understand with Example

The Tutorial illustrate an example from 'JSP for Each'. To understand the example we make use of forEach JSTL tag in jsp. We have used the tag <c:forEach> in order to iterate over the data. The example shows that we are creating a loop to print the natural numbers from 1 to 5 using the attribute begin ="1" and end= "5". The <c.out> print the numbers on the browser.

 

 

Here is the code of foreach.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<body>
<c:out value="The numbers are: " /><br>
<c:forEach var="num" begin="1" end="5" step="1">
<c:out value="${num}" />
<br>
</c:forEach>
</body>
</html>

Output will be displayed as:

Download Source Code: