I have a problem here in JSTL, I have an array object coming from a request attribute that was set in a servlet. All I want to do is to print the indexes of the array. Any help please? Here’s the code:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/tlds/Functions" prefix="func"%>
<table>
<tr>
<td>
<b>k</b> =
</td>
<td>
<table border="1">
<c:forEach var="i" begin="0" end="${responseVector.length}">
<tr>
<td>k<sub>${i}</sub></td><!-- I wish to print the indexes here -->
</tr>
</c:forEach>
</table>
</td>
<td>
<table border="1">
<c:forEach var="i" items="${responseVector}">
<tr>
<td>${func:roundOff(i, 4)}</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
</table>
<br/>
In the code above, responseVector is a double array object, but I want the variable i in the first loop to print the indexes of the array object each time the loop iterates. My expected output is: k0, k1, k2, … but am having an exception instead.
Try this: (Use
varStatusattribute)${status.index}will give you:More info here.