Run Your Application
To run our Spring MVC Application right-click on your project > Run As > Run on Server. And run your application as shown in the below image as depicted below as follows:
After that use the following URL to run your controller
http://localhost:8080/simple-calculator/w3wiki.org/jstldemo
Output:
So on the output screen, you can see both the list with and without Iteration.
Spring MVC – Iterating List on JSP using JSTL
JSP Standard Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. JSTL aims to provide an easy way to maintain SP pages The use of tags defined in JSTL has Simplified the task of the designers to create Web pages. They can now simply use a tag related to the task that they need to implement on a JSP page.
To read more in-depth about JSTL refer to this article: JSP Standard Tag Library
To iterate a List on JSP, the <c:forEach> is a commonly used.
Syntax:
For example, ${list} points to a List<Object>, then the following
<c:forEach var="item" items="${list}" > ${item} </c:forEach>
does basically the same as following in “core Java”:
for (Object item : list) { System.out.println(item); }
In this article, we are going to discuss how can we iterate the List on JSP using JSTL in detail with an example project in Spring MVC.
Contact Us