0

这是我的 JSP 代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ page import="com.lowagie.text.DocumentException" %>
 <%@ page import="org.xhtmlrenderer.pdf.ITextRenderer" %>
 <%@ page import="java.io.FileNotFoundException" %>
 <%@ page import="java.io.FileOutputStream" %>
 <%@ page import="java.io.IOException" %>
 <%@ page import="java.io.File" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

final ITextRenderer iTextRenderer = new ITextRenderer();
iTextRenderer.setDocument("http://localhost:8080/MyApp/test.jsp");
iTextRenderer.layout();
final FileOutputStream fileOutputStream =new FileOutputStream(new File("invoice.pdf"));
iTextRenderer.createPDF(fileOutputStream);
fileOutputStream.close();
%>

</body>
</html>

当我运行这个时,我得到错误......

这是完整的堆栈跟踪...

org.xhtmlrenderer.util.XRRuntimeException: Could not instantiate any SAX 2 parser, including JDK default. The name of the class to use should have been read from the org.xml.sax.driver System property, which is set to: 
    org.xhtmlrenderer.resource.XMLResource.newXMLReader(XMLResource.java:153)
    org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:170)
    org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
    org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
    org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
    org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
    org.apache.jsp.pdftest_jsp._jspService(pdftest_jsp.java:78)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

如何修复错误?

4

1 回答 1

0

这是错误:

XRRuntimeException:无法实例化任何 SAX 2 解析器,包括 JDK 默认值。要使用的类的名称应该从 org.xml.sax.driver System 属性中读取,该属性设置为:

解决方法是定义org.xml.sax.driver。例如,下载 Xerces 并在 Tomcat(或您正在使用的任何东西)中设置此 JVM 选项:

-Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser

更多细节在这里:http ://www.ibm.com/developerworks/xml/library/x-tipsaxp/

于 2013-07-06T17:28:40.140 回答