我试图生成通过以下的servlet动态PDF文件。
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Document Object
import com.itextpdf.text.Document;
//For adding content into PDF document
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.DocumentException;
public class CreatePDFExample extends HttpServlet {
//invoked from doGet method to create PDF through servlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Set content type to application / pdf
//browser will open the document only if this is set
response.setContentType("application/pdf");
//Get the output stream for writing PDF object
OutputStream out=response.getOutputStream();
try {
Document document = new Document();
/* Basic PDF Creation inside servlet */
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph("Tutorial to Generate PDF using Servlet"));
document.add(new Paragraph("PDF Created Using Servlet, iText Example Works"));
document.close();
}
catch (DocumentException exc){
throw new IOException(exc.getMessage());
}
finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "This Servlet Generates PDF Using iText Library";
}
}
但我收到以下错误:
Error 500--Internal Server Error
java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException
at CreatePDFExample.processRequest(CreatePDFExample.java:24)
at CreatePDFExample.doPost(CreatePDFExample.java:47)
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:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
我使用的WebLogic应用服务器8.1 ....我使用iTextPDF。 所以我已经为JAR文件的CLASSPATH。
CLASSPATH:
D:\itextpdf-5.3.4.jar;D:\servlet-2-3.jar;.;
PATH:
C:\Program Files (x86)\Java\jdk1.6.0_14\bin;.;
请告诉我为什么我收到这个错误????我花了很多的时间this.Not越来越小problem.Please帮我在这。
谢谢
后做的事情。我建议得到以下错误
Error 500--Internal Server Error
java.lang.ExceptionInInitializerError
at com.itextpdf.text.pdf.PdfWriter.(PdfWriter.java:1403)
at CreatePDFExample.processRequest(CreatePDFExample.java:26)
at CreatePDFExample.doPost(CreatePDFExample.java:47)
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:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Caused by: java.lang.NullPointerException
at java.lang.Class.privateGetDeclaredFields(Class.java:1488)
at java.lang.Class.getDeclaredFields(Class.java:1073)