JSTL: for each and scoped variable
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:set var="names" value="Joe, Zhou" scope="page" />
<html>
<head>
<title>forEach and status</title>
</head>
<body>
<h1>The forEach tag exposes a scoped variable called 'count', which
is the position of the current iteration of the collection.</h1>
<h2>(Note, it is <i>not</i> the position of the element in the
underlying collection)</h2>
<c:forEach items="${pageScope.names}"
var="currentName"
varStatus="status"
>
Family member #<c:out value="${status.count}" /> is
<c:out value="${currentName}" /> <br />
</c:forEach>
</body>
</html>
Related examples in the same category