Java Reference
In-Depth Information
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The main difference between this JRXML template and the one we've been using for
most of our examples is the addition of the <fieldDescription> element for each
field. The purpose of the <fieldDescription> element is to map the field name
with the appropriate element in the XML file. In this particular example, field names
match the corresponding XML elements. However, this is not always the case, and so
<fieldDescription> elements are required for XML datasources.
The JRDataSource implementation we need to use to create reports from XML files
is called net.sf.jasperreports.engine.data.JRXmlDataSource . The following
example demonstrates how to use it:
package net.ensode.jasperbook;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
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.JasperRunManager;
import net.sf.jasperreports.engine.data.JRXmlDataSource;
public class XmlDSReportServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
ServletOutputStream servletOutputStream = response
getOutputStream();
InputStream reportStream = getServletConfig().getServletContext()
.getResourceAsStream("/reports/XmlAircraftReport.jasper");
try
{
 
Search WWH ::




Custom Search