Hi all,

I'm trying return an xml page based on a simple sql query.  I thought that this would 
be easily done using the JSTL sql tags. How do I access the Struts datasource from the 
jsp?  What should the value of my 'dataSource' element in the 'sql:query' tag be?  I 
haven't been able to get it work and I couldn't find any clues in the archive.

Secondly, is this method looked down upon because I'm accessing the database from my 
jsp?  I have written Actions that access the database, but how can I pass the result 
object to the jsp so that I can easily output it using the 'c.out' tags from JSTL?

Thanks,

Paul


Here is my datasource as defined in struts-config.xml:

<data-source key="db_pool">
  <set-property property="autoCommit" value="false" />
  <set-property property="description" value="Data Source" />
  <set-property property="driverClass" value="com.mysql.jdbc.Driver" />
  <set-property property="url" value="jdbc:mysql://localhost/database" />
  <set-property property="user" value="username" />
  <set-property property="password" value="password" />
  <set-property property="maxCount" value="4" />
  <set-property property="minCount" value="2" />
</data-source>


Here is my test.jsp:

<%@ page contentType="text/xml" %>
<%@ page import="java.util.*" %>
<%@ taglib uri="/tags/jstl-c" prefix="c" %>
<%@ taglib uri="/tags/jstl-sql" prefix="sql" %>

<sql:query var="results" dataSource="db_pool">
  SELECT task_id,task_def_id,approve_date
    FROM tasks
</sql:query>

<?xml version="1.0" encoding="UTF-8"?>
<tasks>
  <c:forEach var="result" begin="0" items="${results.rows}">
    <task>
      <approve-date><c:out value="${result.approve_date}"/></approve-date>
      <task-id><c:out value="${result.task_def_id}"/></task-id>
    </task>
  </c:forEach>
</tasks>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to