Tuesday, March 13, 2007

Preventing new lines in JSP's generated servlets

Good tip from Dr. Chuck: don't use the following for your JSPs:

<%@ page import="cgl.gis.wfs.webservice.*"%>
<%
String beginDate=request.getParameter("beginDate");
...
out.println("stuff");
%>

The generated servlet will include

out.println('\n');

which will put a blank line at the top of your output. This can cause problems if you are using JSP to generate (for example) XML feeds, since the XML header line must be the first line.

To fix, use instead

<%@ page import="cgl.gis.wfs.webservice.*"%><%
String beginDate=request.getParameter("beginDate");
...
out.println("stuff");
%>

No comments: