Debugging rows gotten by JSTL sql:query
I have some questions written in this article. Sometimes I want to handle the data gotten by sql:query, those can be accessed with the expression like ${row.id}.
I don't know the class using as row in following JSTL. At first, trying to clear what kind of class of row.
<sql:query var="rs" dataSrouce="someDataSource"> SELECT ID, NAME FROM EMP </sql:query> <c:forEach var="row" items="${rs.rows}"> <c:out value="${row.id}" />:<c:out value="${row.name}" /> </c:forEach>
I'm not sure what kind of class of row. So changing above code to like below.
<c:forEach var="row" items="${rs.rows}"> <%= pageContext.findAttribute("row").getClass().getName() %> </c:forEach>
And then, I found that row is a java.util.TreeMap. I'm not sure that sql:query always returns the List of java.util.TreeMap, but it is true in my test environment at least. So, I can access the data included into the row with the following code.
<c:forEach var="row" items="${rs.rows}"> <% StringBuffer sb = new StringBuffer(); java.util.TreeMap m = (java.util.TreeMap)pageContext.findAttribute("row"); sb.append(m.get("id")).append(":").append(m.get("name")); out.print(sb.toString()); %> </c:forEach>