Java Reference
In-Depth Information
As we can see, the preceding JRXML template contains no fields nor any kind of
dynamic data. It simply generates some static text on the final report.
In the given JRXML template, we chose to add an XML
CDATA section between the <text> and </text> tags.
Although not strictly necessary in this case, doing so allows
us to easily modify the text between those tags to include
text that would prevent the XML from parsing successfully.
After compiling this report, the binary template EmptyDataSource.jasper is created
in the file system. We can use the following servlet code to fill the report, and stream
it as a PDF to the web browser:
package net.ensode.jasperbook;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
public class EmptyDSReportServlet extends HttpServlet
protected void doGet(HttpServletRequest request,HttpServletResponse
response) throws ServletException, IOException
ServletOutputStream servletOutputStream =
InputStream reportStream = getServletConfig().getServletContext()
servletOutputStream, new HashMap(), new JREmptyDataSource());
Search WWH ::

Custom Search