test.jsp
Example 1:
prints,
Example 2:
Example 1:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String[] arr = new String[] {"dog", "cat", "pig", "cow"};
application.setAttribute("arrayAttribute", arr);
%>
<table border="1">
<c:forEach var="element" items="${arrayAttribute}" varStatus="c">
<tr><td>${c.count}</td>
<td>${element}</td></tr>
</c:forEach>
</table>
prints,
1 | dog |
2 | cat |
3 | pig |
4 | cow |
Example 2:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String[] arr = new String[] {"dog", "cat", "pig", "cow", "horse", "rhino", "hippo"};
application.setAttribute("arrayAttribute", arr);
%>
<table border="1">
<c:forEach var="element" items="${arrayAttribute}" varStatus="c" begin="1" end="5" step="2">
<tr><td>${c.count}</td>
<td>${element}</td></tr>
</c:forEach>
</table>
prints,
1 | cat |
2 | cow |
3 | rhino |
No comments:
Post a Comment