Refer to table columns by index in JSTL
With JSTL it is easy to display query results on a web page. Most online tutorials list code similar to the following:
<sql:query var="queryResults" dataSource="${dataSrc}">
select * from employees
</sql:query>
<c:forEach var="row" items="${queryResults.rows}">
<c:out value="${row.id}"/>
<c:out value="${row.lastname"/>
</c:forEach>
What if you want to display table values referring to the multiple array which is the result set by column index instead of column name. You should use the following syntax:
<c:out value="${row [0]}"/>
<c:out value="${row [1]}"/>
However, it is not enough. When you use the forEach tag, you should also use rowsByIndex property of the Result object as follows:
<c:forEach var="row" items="${queryResults.rowsByIndex}">
Only then your jsp will be valid and will not throw an exception.
