<document>
<header>
<product>resin</product>
<title>JSP FAQ</title>
<description>
</description>
</header>

<body>
<summary objsummary-in-localtoc='1'/>

<faq title="Why I am getting extra whitespace in the output of my JSP?">
<description>
<p>I'm getting a lot of whitespace in my JSP that I don't intend to be there.
Why is it appearing and how can I get rid of it?</p>
</description>

<p>The extra whitespace is coming from newlines, often at the end of
declaration lines at the beginning of the JSP.  For example, the following
jsp:</p>

<example> 
&lt;%@ page import='java.util.*' %&gt;
&lt;%@ page import='java.io.*' %&gt;
Hello world
</example> 

<p>Has newlines in these locations:</p>

<example> 
&lt;%@ page import='java.util.*' %&gt;<b>NL</b>
&lt;%@ page import='java.io.*' %&gt;<b>NL</b>
Hello world<b>NL</b>
</example> 

<p>The result contains the newlines, which may be surprising:</p>

<results> 


Hello world
</results> 

<p>One solution is to let the JSP tag extend across the newline:</p>
<example>
&lt;%@     page import='java.util.*'
%&gt;&lt;%@ page import='java.io.*'
%&gt;Hello world
</example>

<p>Another solution is to use JSP comments to remove the newlines:</p>

<example>
&lt;%@ page import='java.util.*' %&gt;&lt;%--
--%&gt;&lt;%@ page import='java.io.*' %&gt;&lt;%--
--%&gt;Hello world
</example>

<p>Another solution is to use the XML syntax of JSP. Parsing of XML causes
removal of extra whitespace.</p>

<example>
&lt;jsp:root&gt;
&lt;jsp:directive.page import="java.util.*"/&gt;
&lt;jsp:directive.page import="java.io.*"/&gt;

&lt;jsp:text&gt;Hello world&lt;/jsp:text&gt;
&lt;/jsp:root&gt;
</example>

<p>Resin also supports the use of the '\' character to eat whitespace (this is
a Resin specific feature):</p>

<example>
&lt;%@ page import='java.util.*' %&gt;\
&lt;%@ page import='java.io.*' %&gt;\
Hello world
</example>
</faq>

</body>
</document>
