Click to See Complete Forum and Search --> : pass jstl sql query result to jsp


vik111
08-21-2009, 07:09 PM
Hi I have the following code which works perfectly

<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<sql:setDataSource dataSource="jdbc/dbtest"/>

<sql:query var="items" sql="SELECT * FROM homepagesubscriptions">
</sql:query>

<table border="0" align="center" valign="top">

<c:forEach var="row" items="${items.rows}" begin = "0" end="10" >
<tr>
<td>
<img src="${row.imgurl}" width="100" height = "100"></a>
</td>
<tr>
</c:forEach>
</table>

Now what I want is to perform the query in one page and then display the data in another, as such
index.jsp
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<sql:setDataSource dataSource="jdbc/dbtest"/>

<sql:query var="items" sql="SELECT * FROM homepagesubscriptions">
</sql:query>

<!-- NOT SURE WHAT TO DO HERE

<jsp:useBean id="resultBean" scope="request"
class="javax.servlet.jsp.jstl.sql.ResultSupport" />
<jsp:setProperty name="rs" property="rs" />
<jsp:forward page="test.jsp" />
-->


test.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="items" value="${resultBean}" />

<table border="0" align="center" valign="top">

<c:forEach var="row" items="${items.rows}" begin = "0" end="10" >
<tr>
<td>
<img src="${row.imgurl}" width="100" height = "100"></a>
</td>
<tr>
</c:forEach>
</table>

I know in index.jsp I can use jsp forward and usebean but am not sure how to? What type is the result from the query? thanks

JavaServlet
08-25-2009, 05:57 PM
You need a request scope.

I still recommend you use a Servlet Controller to work with JSP and SQL.