这是我的 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)
如何修复错误?