I am trying to iterate through a 2d array of integers and represent them in a grid using the <table>
tag. The catch is that I am not allowed to use any java-script. I know it is something to the effect of the below code, but more complicated. And boardArray
returns a 2d integer array. So how would I extract the value at each cell? There is a predetermined size of the array as well.
<c:forEach var="array" items="${bean.boardArray}">
<tr>
<td>${print out contents of a row}</td>
</tr>
</c:forEach>
You can't do that with plain HTML. You've mentioned HTML in the original question title, but since you've attached the
javabeans
tag and mentioned thec:forEach
tag, I suppose you mean JSP and JSTL instead of HTML.Here the JSP+JSTL solution, formatted to be better readable. The bean code:
Here the JSP file content:
The array content is rendered by two nested
c:forEach
loops. The outer loop iterates over the rows, and for each row, the nested loop iterates over the columns in the given row.Above example looks like this in a browser: