I have designed jasper report using iReport
version (4.7.1). Through iReport it works fine. When I called from java servlet, I get an error:
Error : `Document root element "jasperReport", must match DOCTYPE root "null".`
net.sf.jasperreports.engine.JRException: Document root element "jasperReport",
must match DOCTYPE root "null".
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:242)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:225)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:213)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:167)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:151)
at com.crmreport.controller.ReportServlet.processRequest(ReportServlet.java:124)
at com.crmreport.controller.ReportServlet.doPost(ReportServlet.java:505)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:165)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.xml.sax.SAXParseException: Document root element "jasperReport",must match DOCTYPE root "null".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Err
orHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootEleme
ntSpecified(XMLDTDValidator.java:1621)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleSta
rtElement(XMLDTDValidator.java:1900)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElem
ent(XMLDTDValidator.java:764)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanStartElement(XMLDocumentFragmentScannerImpl.java:1357)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$Conten
tDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1289)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3084)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$Prolog
Driver.next(XMLDocumentScannerImpl.java:912)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
MLDocumentScannerImpl.java:645)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.
java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Ab
stractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1745)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:
238)
This is my JRXML file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
name="BusinessUnitDetail"
pageWidth="595"
pageHeight="842"
columnWidth="535"
leftMargin="20"
rightMargin="20"
topMargin="20"
bottomMargin="20"
uuid="22e233b2-d42c-4a93-87c6-a1d23bd3f7ca">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false" pdfFontName="Times-Bold"/>
<style name="SubTitle" forecolor="#CCCCCC" fontName="Times New Roman" fontSize="18" isBold="false" pdfFontName="Times-Roman"/>
<style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true" pdfFontName="Times-Roman"/>
<style name="Detail" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman"/>
<style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#F0EFEF"/>
</conditionalStyle>
</style>
<parameter name="dateFrom" class="java.util.Date">
<property name="dateFrom" value="new java.util.Date()"/>
<defaultValueExpression><![CDATA[new java.util.Date()]]></defaultValueExpression>
</parameter>
<parameter name="dateTo" class="java.util.Date">
<property name="dateTo" value="new java.util.Date()"/>
<defaultValueExpression><![CDATA[new java.util.Date()]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
BusinessUnit AS BusinessUnit,
CallStart AS CallStart,
CallEnd AS CallEnd,
CallTakenBy AS CallTakenBy,
CalledDate AS CalledDate,
CallPersonName AS CallPersonName,
Duration AS Duration
FROM
crmcalldetail
WHERE CalledDate > $P{dateFrom} AND CalledDate < $P{dateTo}
ORDER BY BusinessUnit]]>
</queryString>
<field name="BusinessUnit" class="java.lang.String"/>
<field name="CallStart" class="java.sql.Time"/>
<field name="CallEnd" class="java.sql.Time"/>
<field name="CallTakenBy" class="java.lang.String"/>
<field name="CalledDate" class="java.sql.Date"/>
<field name="CallPersonName" class="java.lang.String"/>
<field name="Duration" class="java.lang.Integer"/>
<variable name="duration_sum" class="java.lang.Integer" resetType="Group" resetGroup="BusinessUnit" calculation="Sum">
<variableExpression><![CDATA[$F{Duration}]]></variableExpression>
</variable>
<variable name="duration_tot" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{Duration}]]></variableExpression>
</variable>
<group name="BusinessUnit">
<groupExpression><![CDATA[$F{BusinessUnit}]]></groupExpression>
<groupHeader>
<band height="37">
<frame>
<reportElement uuid="e53feaa2-4fce-4233-873c-4c5b1d87bd09" mode="Opaque" x="0" y="7" width="555" height="24" forecolor="#B89F7D" backcolor="#000000"/>
<textField isStretchWithOverflow="true">
<reportElement uuid="8a34951d-becf-4676-801f-1cbfd81518b9" style="SubTitle" isPrintRepeatedValues="false" x="2" y="0" width="479" height="24" forecolor="#FF6600"/>
<textElement>
<font isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{BusinessUnit}]]></textFieldExpression>
</textField>
</frame>
</band>
</groupHeader>
<groupFooter>
<band height="26">
<textField pattern="###0">
<reportElement uuid="6a2e9f4f-bc0c-4deb-a861-9d30221cc566" x="481" y="9" width="48" height="15" forecolor="#FF3300"/>
<textElement textAlignment="Right">
<font size="11" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{duration_sum}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="194" splitType="Stretch">
<image>
<reportElement uuid="97326b0b-4f59-45fa-bab1-82019da4a8f6" x="456" y="0" width="99" height="117"/>
<imageExpression><![CDATA["cherry.jpg"]]></imageExpression>
</image>
<frame>
<reportElement uuid="643a9f59-1f72-4def-a457-944bebb9111a" mode="Opaque" x="0" y="0" width="451" height="95" backcolor="#000000"/>
<staticText>
<reportElement uuid="c2fa629b-41e3-4ea6-ba69-458367963aac" style="Title" x="0" y="0" width="451" height="66"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[Call Tracker Report]]></text>
</staticText>
<staticText>
<reportElement uuid="a01a3826-af92-4941-ab2b-41cb1da3f9a6" style="SubTitle" x="157" y="66" width="249" height="29"/>
<textElement>
<font size="22" isBold="false"/>
</textElement>
<text><![CDATA[X-ONT Software (Ltd) Ltd]]></text>
</staticText>
</frame>
<frame>
<reportElement uuid="3d131a89-bb0f-4d0a-8085-85ef01af5910" mode="Opaque" x="0" y="96" width="451" height="21" forecolor="#000000" backcolor="#CC0000"/>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement uuid="580213d0-b1fc-4725-b311-c89e960a4ce0" x="303" y="1" width="144" height="20" forecolor="#FFFFFF"/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
<staticText>
<reportElement uuid="99c5e0a7-c15a-4072-b1ff-8b83a347f161" x="2" y="121" width="74" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Customer ]]></text>
</staticText>
<staticText>
<reportElement uuid="cfe1a411-8270-4b02-947c-a699ff86c385" x="205" y="121" width="56" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Called By]]></text>
</staticText>
<staticText>
<reportElement uuid="bc57e2ae-3f68-4376-9d87-97c2c984a679" x="363" y="121" width="100" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Called Taken By]]></text>
</staticText>
<staticText>
<reportElement uuid="ba3f773c-9145-4e37-9ffe-70dc2e1acefd" x="204" y="143" width="65" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Report Type]]></text>
</staticText>
<staticText>
<reportElement uuid="948a2d75-1716-414e-b2e9-4b3ab44382ca" x="2" y="143" width="74" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Group Type]]></text>
</staticText>
<staticText>
<reportElement uuid="1eb88a37-9aa5-4368-8e4d-fcf02b95a6bb" x="85" y="121" width="67" height="20"/>
<textElement/>
<text><![CDATA[ALL]]></text>
</staticText>
<staticText>
<reportElement uuid="b4d0efcf-fc10-4cd7-a946-786ee3d7865f" x="284" y="121" width="48" height="20"/>
<textElement/>
<text><![CDATA[ALL]]></text>
</staticText>
<staticText>
<reportElement uuid="b4d0efcf-fc10-4cd7-a946-786ee3d7865f" x="473" y="121" width="48" height="20"/>
<textElement/>
<text><![CDATA[ALL]]></text>
</staticText>
<staticText>
<reportElement uuid="37f5f2ec-f1c2-4837-b0bb-3b4dfde170d0" x="282" y="143" width="100" height="20"/>
<textElement/>
<text><![CDATA[Detail]]></text>
</staticText>
<staticText>
<reportElement uuid="2be6789f-c973-417f-b32a-44822d417a98" x="84" y="143" width="100" height="20"/>
<textElement/>
<text><![CDATA[CustomerCalled]]></text>
</staticText>
<staticText>
<reportElement uuid="f40bab96-7309-41d1-a874-f2b99a9f16bc" x="2" y="165" width="74" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Date From]]></text>
</staticText>
<staticText>
<reportElement uuid="692e0148-3beb-4c22-b193-36e37254421e" x="205" y="167" width="63" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Date To]]></text>
</staticText>
<textField pattern="yyyy-MM-dd">
<reportElement uuid="d0e85180-f225-4a6a-ae0d-7927da8212db" x="84" y="167" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{dateFrom}]]></textFieldExpression>
</textField>
<textField pattern="yyyy-MM-dd" isBlankWhenNull="true">
<reportElement uuid="43ea7f44-ebfd-459e-a9c1-dbbe89168f0b" x="282" y="167" width="83" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{dateTo}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="29" splitType="Stretch">
<staticText>
<reportElement uuid="3284a455-7c75-40df-838b-34ec9fc5489e" style="Column header" x="297" y="5" width="76" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Satrt]]></text>
</staticText>
<staticText>
<reportElement uuid="c41f01fd-3417-4cd2-a8d9-296069637903" style="Column header" x="384" y="5" width="67" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[End]]></text>
</staticText>
<staticText>
<reportElement uuid="95576a18-8fe1-4d57-bef4-c3361481475c" style="Column header" x="107" y="5" width="92" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[CallTakenBy]]></text>
</staticText>
<staticText>
<reportElement uuid="1ff784cc-a3ab-4f0e-931d-6924a48e5299" style="Column header" x="199" y="5" width="92" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement uuid="4c7fd897-81e9-4711-99d1-de26c6f86a47" style="Column header" x="2" y="4" width="92" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Called By]]></text>
</staticText>
<staticText>
<reportElement uuid="6033972d-b1d4-4154-9df2-24cba2a403dd" style="Column header" x="471" y="5" width="58" height="18" forecolor="#000000"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Duration]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" splitType="Stretch">
<frame>
<reportElement uuid="ccc5fd50-0293-441b-b783-e95672e038a1" style="Row" mode="Opaque" x="0" y="0" width="555" height="18"/>
<textField isStretchWithOverflow="true" pattern="h.mm a">
<reportElement uuid="a317f374-5796-43c4-99d6-10a3af7ee4db" style="Detail" positionType="Float" x="297" y="0" width="92" height="18"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{CallStart}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement uuid="442d310e-4052-4ccb-96e0-636b268a55e7" style="Detail" positionType="Float" x="107" y="0" width="92" height="18"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{CallTakenBy}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="dd-MMM-yy">
<reportElement uuid="74fca3b3-8be6-40b5-8556-eddf64295fd3" style="Detail" positionType="Float" x="199" y="0" width="92" height="18"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{CalledDate}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement uuid="2dcf814d-af5b-4aa9-9fb3-a70948156bf3" style="Detail" positionType="Float" x="2" y="0" width="92" height="18"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{CallPersonName}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="###0">
<reportElement uuid="b0db0027-f5f2-4126-a400-16e0b5a1d0ba" style="Detail" positionType="Float" x="481" y="0" width="48" height="18"/>
<textElement textAlignment="Right">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{Duration}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="h.mm a">
<reportElement uuid="89479c74-1d4f-4e50-bc8c-3577a6081433" style="Detail" positionType="Float" x="389" y="0" width="92" height="18"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{CallEnd}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
<columnFooter>
<band height="35" splitType="Stretch">
<line>
<reportElement uuid="4de509a0-2c1a-494e-80ba-26495de7e795" positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
<textField pattern="###0" isBlankWhenNull="true">
<reportElement uuid="daab26a1-72f8-48bb-aea6-3265520641c2" x="458" y="4" width="71" height="20" forecolor="#990000"/>
<textElement textAlignment="Right">
<font size="14" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{duration_tot}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="aecf8666-74fc-4ff3-8a1b-3a4e548d5d69" x="307" y="4" width="149" height="20" forecolor="#990000"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Net Total Minutes]]></text>
</staticText>
</band>
</columnFooter>
<pageFooter>
<band height="25" splitType="Stretch">
<frame>
<reportElement uuid="57d220fb-781d-4991-a9e4-1b7006fea841" mode="Opaque" x="0" y="1" width="555" height="24" forecolor="#D0B48E" backcolor="#000000"/>
<textField evaluationTime="Report">
<reportElement uuid="59953dfc-6b53-4411-a003-74cd5d551432" style="Column header" x="513" y="0" width="40" height="20" forecolor="#FFFFFF"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8a2577bd-ce1b-47e5-87bf-74e7627e89a3" style="Column header" x="433" y="0" width="80" height="20" forecolor="#FFFFFF"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement uuid="c36f2f3c-cae1-4e1a-889e-37c3a5862d5f" style="Column header" x="2" y="1" width="197" height="20" forecolor="#FFFFFF"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
This is what I run:
JasperReport jasperReport = null;
JasperDesign jasperDesign = null;
Map parameters = new HashMap();
parameters.put("dateFrom", dateFrom);
parameters.put("dateTo", dateTo);
String path = getServletContext().getRealPath("/WEB-INF/");
System.out.println("==Path==" + path);
String filePath = path+"\\classes\\com\\crmreport\\controller\\BusinessUnitDetail.jrxml";
System.out.println("==filePath==" + filePath);
jasperDesign = JRXmlLoader.load(filePath);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
byte[] byteStream = JasperRunManager.runReportToPdf(jasperReport, parameters, new JREmptyDataSource());
OutputStream outStream = response.getOutputStream();
response.setHeader("Content-Disposition","inline, filename=BusinessUnitDetail.pdf");
response.setContentType("application/pdf");
response.setContentLength(byteStream.length);
outStream.write(byteStream,0,byteStream.length);
What causes these errors? I googled it, it say error is on XML. But it worked fined using iReport.