Get index of a foreach - Struts, JSTL, FreeMarker

How to get the index of the current iteration of a foreach loop in Struts2, JSTL, FreeMarker

Struts 2

<s:iterator value="userList" status="status" >    
    <s:property value="#status.index" />
    <s:property value="firstname" />



<c:forEach items="${userList}" var="u" varStatus="status">

    <c:out value="${status.index}" />
    <c:out value="${u.firstname}" />



<#list userList as u>

Backend code
List<User> userList = new ArrayList<User>();

userList.add(new User("sam", "jay"));
userList.add(new User("sameera", "jaya"));

No comments:

Post a Comment