Peter Pilgrim wrote:
>
> How do get a JSP to write a properly formatted CSV file?
> Is there a way to make JSP stop adding new lines or spaces?
> Can JSP pack spaces tightly between <% .. %> and <tag> ...</tag>?
JSP follows the lead from XML with regards to line feeds: they are
preserved but ignored.
So the trick is to make sure you don't add any line feeds in the
JSP page where you don't want them. In your sample, you have a
line feed character after all JSP directives and action elements.
When the JSP container processes the page, it consumes the JSP
elements but adds the line feed characters to the response.
By placing ending and starting the JSP elements on the same line,
you get rid of all of the unwanted line feeds:
<%@ taglib uri="/orataglib"
prefix="ora" %><%@ taglib uri="/emistaglib"
prefix="emis" %><%@ page
import="com.ora.jsp.util.*" %><%@ page
import="com.ora.jsp.sql.*" %><%@ page language="java"
contentType="application/vnd.ms-excel" %><jsp:useBean
id="detailBean" class="com.db.gdd3.emis.report.ReportDetailBean"
scope="request" /> ...
and so on for all JSP elements.
I describe this in Chapter 12 of my book, in relation to WML
since WML browsers are sometimes picky about this stuff.
> Conversely can JSP be to told print a new line directly
> ( java.io.PrintStream.println() )?
Any line feed in the JSP page is preserved, so just put a line
feed where you need it. In a custom action tag handler or a bean
that writes to the response, you can use JspWriter.newLine();
Hans
> Any help appreciated?
>
> BTW: This is my JSP and it uses O'Reilly Taglib library to do the
> iteration from DB SQL Query.
>
> <%@ taglib uri="/orataglib" prefix="ora" %>
> <%@ taglib uri="/emistaglib" prefix="emis" %>
> <%@ page import="com.ora.jsp.util.*" %>
> <%@ page import="com.ora.jsp.sql.*" %>
> <%@ page language="java" contentType="application/vnd.ms-excel" %>
> <jsp:useBean id="detailBean"
> class="com.db.gdd3.emis.report.ReportDetailBean"
> scope="request" />
> <jsp:useBean id="sqlBean"
> class="com.db.gdd3.emis.sql.ExpressoSQLCommandBean"
> scope="request" />
>
> <ora:loop name="sqlBean" property="columnNameList"
> loopId="columnName" className="java.lang.String" >
> <%= columnName %>,
> </ora:loop>
>
> <ora:loop name="rowsetData" loopId="row" className="Row" >
> <ora:loop name="row" property="columns"
> loopId="col" className="Column" >
> <jsp:getProperty name="col" property="string" />,
> </ora:loop>
> </ora:loop>
--
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