JRXML无法加载

时间:2013-05-28 09:16:59

标签: java jasper-reports

但是我尝试加载我的JRXML,我一直收到这个错误:

net.sf.jasperreports.engine.JRException: org.xml.sax.SAXException: http://java.sun.com/xml/jaxp/properties/schemaSource

这是我的代码:

public class DownloadService {
    public static final String TEMPLATE = "C:/reports/report.jrxml";
    protected static Logger logger = Logger.getLogger("service");

    Connection conn;

    public void download(String type, HashMap params, HttpServletResponse response) throws FileNotFoundException {
        try {
            //conn =jspDAO.getSqlSession().getConnection();

            try {
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                conn = DriverManager.getConnection(
                        "jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:test", "test",
                        "test"); //censored
                System.out.println("Getting connection.....");
                System.out.println(conn);
            } catch (Exception e) {
                e.printStackTrace();
            }


            InputStream reportStream = new FileInputStream(TEMPLATE);
            System.out.println("Retrieved template");
            // 3. Convert template to JasperDesign
            System.out.println("Loading jrxml");
            System.out.println(reportStream.toString());
            JasperDesign jd = JRXmlLoader.load(reportStream);
            System.out.println("Loaded jrxml");
            // 4. Compile design to JasperReport
            System.out.println("Compiling JasperReport");
            JasperReport jr = JasperCompileManager.compileReport(jd);
            System.out.println("Compiled JasperReport");
            // 5. Create the JasperPrint object
            // Make sure to pass the JasperReport, report parameters, and data source
            System.out.println("Creating JasperReport");
            JasperPrint jp = JasperFillManager.fillReport(jr, params, conn);
            System.out.println("Created JasperReport");
            // 7. Export report
            System.out.println("Exporting report");
            JasperExportManager.exportReportToPdfFile(jp, "C:/reports/pdfOutput.pdf");
        } catch (JRException jre) {
            logger.error("Unable to process download");
            logger.error(jre);
            throw new RuntimeException(jre);
        }
    }
}

我无法通过JasperDesign jd = JRXmlLoader.load(reportStream);

以下是我的记录器输出的内容:

weblogic.servlet.internal.ServletResponseImpl@a4120d
Getting connection.....
oracle.jdbc.driver.T4CConnection@105036e
Retrieved template
Loading jrxml
java.io.FileInputStream@8aed09
106428815 [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] WARN component.ComponentsEnvironment  - Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
net.sf.jasperreports.engine.JRException: org.xml.sax.SAXException: http://java.sun.com/xml/jaxp/properties/schemaSource
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:243)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:226)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:214)
    at com.jasperreport.biz.DownloadService.download(DownloadService.java:97)
    at com.jasperreport.biz.JasperService.print(JasperService.java:29)
    at com.jasperreport.presentation.JasperController.printReport(JasperController.java:57)
    at com.jasperreport.presentation.JasperController.doPost(JasperController.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
Caused by: org.xml.sax.SAXException: http://java.sun.com/xml/jaxp/properties/schemaSource
    at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1203)
    at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:135)
    at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:152)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:239)
    ... 18 more

这是我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD JasperReport//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<background>
    <band/>
</background>
<title>
    <band height="79"/>
</title>
<pageHeader>
    <band height="35"/>
</pageHeader>
<columnHeader>
    <band height="61"/>
</columnHeader>
<detail>
    <band height="125"/>
</detail>
<columnFooter>
    <band height="45"/>
</columnFooter>
<pageFooter>
    <band height="54"/>
</pageFooter>
<summary>
    <band height="42"/>
</summary>
</jasperReport>

我有什么办法可以解决这个问题吗?

0 个答案:

没有答案