Jasper报告错误:org.xml.sax.SAXParseException:文档根元素" jasperTemplate"

时间:2017-03-08 12:09:55

标签: jasper-reports

我使用jasper-6.2.2版本构建报告。我使用jasper studio 6.2.2版本。而在开发模式下它运行良好。当我在tomcat上部署时,它会给出以下错误。

我使用的是jdk-1.6版本。

我无法理解问题出在哪里。如何解决这个问题。

ERROR [http-8080-5] (Digester.java:1770) - Parse Error at line 3 column 280: Document root element "jasperTemplate", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "jasperTemplate", 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(ErrorHandlerWrapper.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.rootElementSpecified(XMLDTDValidator.java:1621)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1900)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1316)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.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(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1916)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:199)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.load(JRXmlTemplateLoader.java:248)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:173)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.loadTemplate(JRFillReportTemplate.java:119)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.evaluate(JRFillReportTemplate.java:89)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplates(JRBaseFiller.java:740)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplateStyles(JRBaseFiller.java:763)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectStyles(JRBaseFiller.java:711)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.loadStyles(JRBaseFiller.java:658)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:550)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:121)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983)
    at com.gold.eloop.server.reports.overview.OverviewReport.createJasperFile(OverviewReport.java:329)
    at com.gold.eloop.server.remoteservices.OverviewReportServiceRemote.saveImageAndJasper(OverviewReportServiceRemote.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    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:103)
    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.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
net.sf.jasperreports.engine.JRRuntimeException: Error parsing template XML.
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:211)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.load(JRXmlTemplateLoader.java:248)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:173)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.loadTemplate(JRFillReportTemplate.java:119)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.evaluate(JRFillReportTemplate.java:89)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplates(JRBaseFiller.java:740)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplateStyles(JRBaseFiller.java:763)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectStyles(JRBaseFiller.java:711)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.loadStyles(JRBaseFiller.java:658)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:550)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:121)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983)
    at com.gold.eloop.server.reports.overview.OverviewReport.createJasperFile(OverviewReport.java:329)
    at com.gold.eloop.server.remoteservices.OverviewReportServiceRemote.saveImageAndJasper(OverviewReportServiceRemote.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    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:103)
    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.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.xml.sax.SAXParseException: Document root element "jasperTemplate", 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(ErrorHandlerWrapper.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.rootElementSpecified(XMLDTDValidator.java:1621)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1900)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1316)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.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(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1916)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:199)
    ... 37 more

在某处,我读到6.3.1版本包含额外的属性而不是6.2.2版本。最初我使用6.3.1,但后来我把它改为6.2.2,但每当我试图删除" uuid"来自jrxml组件的属性,它会在文件保存时自动返回。

究竟是什么问题,我该怎么办?请有人帮我从这个碧玉报道!!!!! :(

1 个答案:

答案 0 :(得分:2)

错误是由您在报告中使用的JasperReports样式模板(* .jrtx文件)引起的。

在6.3.0之前,样式模板使用了DTD:

<!DOCTYPE jasperTemplate
  PUBLIC "-//JasperReports//DTD Template//EN"
  "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">

从6.3.0开始,模板使用XML模式(但仍然支持DTD以实现向后兼容):

<jasperTemplate xmlns="http://jasperreports.sourceforge.net/jasperreports/template" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/template http://jasperreports.sourceforge.net/xsd/jaspertemplate.xsd">

您的案例中的问题似乎是您在JasperReports 6.2.2中使用6.3.0样式模板。哪个不起作用,请确保您的* .jrtx文件具有DOCTYPE且没有xmlns和xsi:schemaLocation属性。