| ||||||||||
Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ Introduction Compilation EL JSTL Directives Variables Actions Applications Schema for JSP-2.0 .tld files Velocity syntax JSP Templates FAQ |
Why I am getting extra whitespace in the output of my JSP?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: <%@ page import='java.util.*' %> <%@ page import='java.io.*' %> Hello world Has newlines in these locations: <%@ page import='java.util.*' %>NL <%@ page import='java.io.*' %>NL Hello worldNL The result contains the newlines, which may be surprising: Hello world One solution is to let the JSP tag extend across the newline: <%@ page import='java.util.*' %><%@ page import='java.io.*' %>Hello world Another solution is to use JSP comments to remove the newlines: <%@ page import='java.util.*' %><%-- --%><%@ page import='java.io.*' %><%-- --%>Hello world Another solution is to use the XML syntax of JSP. Parsing of XML causes removal of extra whitespace. <jsp:root> <jsp:directive.page import="java.util.*"/> <jsp:directive.page import="java.io.*"/> <jsp:text>Hello world</jsp:text> </jsp:root> Resin also supports the use of the '\' character to eat whitespace (this is a Resin specific feature): <%@ page import='java.util.*' %>\ <%@ page import='java.io.*' %>\ Hello world
|