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
> G.O.A.T
>                     "the Greatest Of All Time"
>
> --
>
> 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.

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
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

Reply via email to