0

So I've set up some SQL tables and just to test and get my head around the data so I can test it. So I use:

SELECT * From Customer
</sql:query>

Now I want to take "result" and print it out the whole table! preferably using the:

<c: out />

Any ideas or better ways?

DonnellyOverflow
  • 3,981
  • 6
  • 27
  • 39

1 Answers1

1

Do the query in a servlet not a JSP. For example, one way would be to put the results of the query in a request attribute and forward from the servlet to a JSP.

In servlet:

request.setAttribute("queryresults", queryresults);
request.getRequestDispatcher("somejsp.jsp").forward(request, response); 

JSP:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...
<table>
    <c:forEach items="${queryresults}" var="row">
        <tr>
            <td>${row.field1}</td>
            <td>${row.field2}</td>
            <td>${row.field3}</td>
        </tr>
    </c:forEach>
</table>

See also How to avoid Java code in JSP files?

Community
  • 1
  • 1
developerwjk
  • 8,619
  • 2
  • 17
  • 33