How to iterate through a ResultSet->List in JSTL?

[nobr]I have a ResultSet that I've converted to a List via:

RowSetDynaClass rsdc =new RowSetDynaClass(rs);

resultList = rsdc.getRows();

and my Stripes JSP has the following:

<c:forEach var="row" items="${resultList}">

${row.prod_id}<br/>

</c:forEach>

but it produces no output, even through the List.size() = 15

Ubuntu 6.06

Netbeans 5.5, built-in Tomcat 5.5.17

Java 1.5[/nobr]

[589 byte] By [r5ta] at [2007-11-27 11:05:59]
# 1

EL variables != scriptlet variables.

EL variables are the attributes in page, request, session and application scope.

To make the list available to the JSP:

request.setAttribute("resultList", resultList);

This should be done in a servlet/bean which then passes control to the JSP for rendering.

Cheers,

evnafets

evnafetsa at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

request.setAttribute("resultList", resultList);

write this line in the JSP coding

and use ${pageScope.resultList} in JSTL

I suggests use JSTL<sql> tag to retrive the data from DB

MiracleShivaa at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

[nobr]It seems to work ok on the bean side, but

<c:forEach var="row" items="${pageScope.resultList.rows}">

<br/>${row.custID} ${row.custName}

</c:forEach>

also returns no results (and no errors).[/nobr]

r5ta at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Got it. Thanks! Solution:

Result result = ResultSupport.toResult(table);

request.setAttribute("result", result);

r5ta at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Just thought I'll mention, resultSet belongs in an isolated persistent layer. You should copy the contents of resultSet to some collection such as List which is then passed to the JSP page for JSTL to list. If you look up MVC java, it will discuss separation of concerns. Also read up on propery using try/catch/finally blocks to open a connection, use it, then close it (all in the same function), and not returning the resultSet outside of the function, but a collection instead. Too much to diccuss to go into this further.

George123a at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

ResultSet should never see the light of day in a JSP, unless it's the smallest of apps where all you want to do is display results of a single page in a JSP.

Even then, I think I'd be careful about exposing important data that way.

Layering is the way to go for all but trivial apps.

%

duffymoa at 2007-7-29 13:12:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...