I / o文件编写代码错误

时间:2014-01-07 11:03:03

标签: java servlets jasper-reports

以下是在main()方法中工作正常的代码。编译并将.jasper文件作为输出

package com;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;

public class JasperCompile {
    public static void main(String args[]) throws JRException {
        JasperCompileManager.compileReportToFile("C:\\temp.jrxml", "C:\\temp.jasper");
    }
}

但是当我将main()方法中的跟随行嵌入到servlet的doGet方法中时,它就不起作用了

JasperCompileManager.compileReportToFile("C:\\temp.jrxml", "C:\\temp.jasper");

以下是堆栈跟踪。

Jan 7, 2014 4:19:21 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [JasperReportsBrowserDemoServlet] in context with path [/PDFReports] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: org.apache.commons.digester.Digester.addSetProperties(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/StringV
at net.sf.jasperreports.components.ComponentsXmlHandler.addListRules(ComponentsXmlHandler.java:117)
at net.sf.jasperreports.components.ComponentsXmlHandler.configureDigester(ComponentsXmlHandler.java:104)
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.addComponentRules(JRXmlDigesterFactory.java:514)
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.configureDigester(JRXmlDigesterFactory.java:493)
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1324)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:108)
at com.JasperReportsBrowserDemoServlet.createJRXML(JasperReportsBrowserDemoServlet.java:136)
at com.JasperReportsBrowserDemoServlet.doGet(JasperReportsBrowserDemoServlet.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
 4:23 PM 

我们在main()方法和服务器端编写代码时会有什么不同?

1 个答案:

答案 0 :(得分:2)

您的Apache Commons Digester版本不正确。查看JasperReport的所有依赖项。