I have previously posted about my whitespace woes, mostly stemming from the
fact that JSP doesn't support any notion of ignoring whitespace (that is JSP
assumes that any whitespace in the input file should appear in the output
file, making it difficult if not impossible to specify the exact appearance
of the output file with respect to whitespace due to issues of JSP tags and
pretty printing).
That said, I stumbled upon a bit of a workaround to the issue. This doesn't
entirely resolve the issue but it helps. First let me illustrate the
problem (I am using 0.92 syntax, but the same applies to 1.0):
~ sample.jsp
<USEBEAN NAME="stateinfo" LIFESPAN="page">
<SETONCREATE BEANPROPERTY="property" VALUE="value">
</USEBEAN>
<USEBEAN NAME="message" LIFESPAN="page"></USEBEAN>
<USEBEAN NAME="folder" LIFESPAN="page"></USEBEAN>
<HTML>
...
</HTML>
~
Now at first glance there doesn't seem to be anything wrong with this file.
But the output actually looks something like this:
~ output from sample.jsp
<HTML>
...
</HTML>
~
Notice the blank lines. This is because the whitespace is preserved from
the input jsp, and so the newlines that make the USEBEAN directives look
pretty to us humans on the server show up in the output file on the client
side.
If you are producing HTML this is fine, but for other content types, this is
not always a good thing (try returning url encoded form values for instance)
So here is the fix:
~ fixed.jsp
<USEBEAN NAME="stateinfo" LIFESPAN="page"><SETONCREATE
BEANPROPERTY="property" VALUE="value"></USEBEAN><% /*
*/ %><USEBEAN NAME="message" LIFESPAN="page"></USEBEAN><% /*
*/ %><USEBEAN NAME="folder" LIFESPAN="page"></USEBEAN><% /*
*/ %><HTML>
...
</HTML>
~
I just use the scriplet tag to comment out the newlines. This works great,
with one exception. Notice I had to join the SETONCREATE tag with it's
surrounding USEBEAN tag so that it is all one line.
This may be JRun specific, but the <% /* */ %> syntax did not get
interpreted by the parser inside the USEBEAN tag and appeared verbatim in
the output. Thus I didn't see any way to comment out the newlines that
appeared as part of the USEBEAN/SETONCREATE pairing, and was forced to join
it all into one line with no whitespace between tag opens and closes.
Hope this helps,
-taylor
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html