Search code examples
spring-mvcjsp-tags

JSP template: is there command for FOR or FOREACH iteration


Im completely newbie in JSP:)

But Im fixing a SPRING/JSP appication. My question is if there is any template command which iterates through collection/table? Like FOREACH or FOR?

Any documentation/examples for it?


Solution

  • You can use JSTL tag library for this. First, you have to add jstl tag library to your JSP page

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    

    and for iterating the list:

    <c:forEach items="${myList}" var="element"> 
      <tr>
        <td>${element.status}</td>
        <td>${element.requestType}</td>
        <td>${element.requestedFor}</td>
        <td>${element.timeSubmitted}</td>
      </tr>
    </c:forEach>