Hans
Thanx. I was thinking along the first option line myself.
I realised that a lot of the reporting in my current project in either HTML, CSV, XML
could be put in a separated JSPs, after I moved DB code to a separate Servlet.
I could make the Servlet perform the DB SQL Query with the SQL Command Bean
then put the bean and resulting rowset data in request scope. Afterwards I forward
to the required ``reporting JSP'' according the requested report type.
Et Voila! !Estupendo! On the way Generic reporting!
Yes Hans, I copied your SQL Command Bean ( I did not subclass because the class
data members were "private" ) and made it work with Expresso Framework's
(www.javacorporate.com) `DBConnection' object. Unfortunately the
`DBConnection' in Expresso 2.20 does not support `PreparedStatement' objects yet!
The other thing I added was access to the ResultSetMetaData indirectly.
I needed to know the column labels, names, and possible the type names of the Row
data. This is where the "Vector [] getColumnNameList()" bean method comes from.
It probably be extended also to get the more RSMD stuff like the "Precision", "Scale"
but this might be overkill for some projects me think.
"I am glad I bought your book. Yours is the most immediately useful JSP book
I have come across so far."
--
Peter Pilgrim
G.O.A.T
"the Greatest Of All Time"
---------------------------------------- Message History
----------------------------------------
From: Hans Bergsten <[EMAIL PROTECTED]>@java.sun.com> on 25/01/2001 16:57 PST
__<CUT>__
Peter Pilgrim wrote:
>
> Quick-fire question can a JSP output a different content type
> such as Comma Separated Value file ``application/vnd.ms-excel' ?
Short answer, yes. One way is to let the users select the type of
input they want in the form (e.g. using radio buttons) and
test on this value in the JSP page you submit to. Depending on the
value, forward to the JSP page that generates the correct type of
response and set the contentType attribute to the appropriate
value in each JSP page with the page directive. I would do all the
database stuff in your example below in the JSP page that is invoked
by the form, and transfer the "sqlBean" and "rowSetData" as request
attributes (request scope objects) to the other JSP pages so they can
render the response.
An alternative is to use one JSP for both formats and set the contentType
dynamically , using <% response.setContentType("whatever"); %>, and
put the parts that generate the different formats within a conditional
block (using either a scriptlet if/else statement, or better, a
conditional custom action such as the ones that are part of the
Struts framework).
Hans
> I got a bean like O'Reilly Command SQL Bean and want to give
> a surfer at choice at form-input time?
>
> first JSP to output HTML table from DB
>
> second JSP to output CSV table with content Type
> (straight into Excel Spreadsheet)?
>
> <jsp:useBean id="sqlBean"
> class="com.db.gdd3.emis.sql.ExpressoSQLCommandBean" >
> <jsp:setProperty name="sqlBean" property="connection"
> value="<%= conx %>" />
> <jsp:setProperty name="sqlBean" property="sqlValue"
> value="SELECT * FROM product_detail WHERE pd_name='Swaptions' " />
> </jsp:useBean>
>
> <%
> Vector rowsetData = sqlBean.executeQuery();
> request.setAttribute( "rowsetData", rowsetData );
> %>
>
> <table border="1" cellpadding="2" cellspacing="1" >
> <tr bgcolor="#0000CC" >
> <ora:loop name="sqlBean" property="columnNameList"
> loopId="columnName" className="java.lang.String" >
> <th>
> <font color="#FFFFFF" >
> <%= columnName %>
> </font>
> </th>
> </ora:loop>
> </tr>
>
> <ora:loop name="rowsetData" loopId="row" className="Row" >
> <tr>
> <ora:loop name="row" property="columns"
> loopId="col" className="Column" >
> <td>
> <jsp:getProperty name="col" property="string" />
> </td>
> </ora:loop>
> </tr>
> </ora:loop>
> </table>
>
> --
> Peter Pilgrim
--<CUT>--
--
This e-mail may contain confidential and/or privileged information. If you are not the
intended recipient (or have received this e-mail in error) please notify the sender
immediately and destroy this e-mail. Any unauthorised copying, disclosure or
distribution of the material in this e-mail is strictly forbidden.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets