Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Failed to load target servlet

  Asked By: Cameron    Date: Sep 13    Category: Java    Views: 1031
  

i have a little problem here
i've created a web project and included the itext.jar
and itext_xml.jar files [as a java library] into it
here's the source
www.lowagie.com/iText/download.html#download
and while i run that code on server


import java.io.IOException;
import javax.servlet.http.HttpServlet;
import java.util.Date;
import javax.servlet.http.*;
import javax.servlet.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.html.HtmlWriter;
public class Chap0105 extends HttpServlet {

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{

// we retrieve the presentationtype
String presentationtype = request.getParameter("presentationtype");

// step 1
Document document = new Document();

try
{

// step 2: we set the ContentType and create an instance of the
corresponding Writer
if ("pdf".equals(presentationtype)) {
response.setContentType("application/pdf");
PdfWriter.getInstance(document, response.getOutputStream());
}
else if ("html".equals(presentationtype)) {
response.setContentType("text/html");
HtmlWriter.getInstance(document, response.getOutputStream());
}
else {

response.sendRedirect("www.lowagie.com/iText/tutorial/ch01.html#step2");
}

// step 3
document.open();

// step 4
document.add(new Paragraph(new Date().toString()));


}
catch(DocumentException de) {
/*de.printStackTrace();
System.err.println("document: " + de.getMessage());*/
}

// step 5: we close the document (the outputstream is also closed
internally)
document.close();

}
}
the WSAD says that

Error Message: Failed to load target servlet [Chap0105]
Error Code: 500
Target Servlet: Chap0105
Error Stack:
java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:254)
at java.beans.Beans.instantiate(Beans.java:213)
at java.beans.Beans.instantiate(Beans.java:57)
.............etc

why it keeps on tellin' me failed to load target servlet
while nearly the same code run in a java project

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
public class Chap0101 {

public static void main(String[] args) {

System.out.println("Chapter 1 example 1: Hello World");

// step 1: creation of a document-object
Document document = new Document();

try {

// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file

PdfWriter.getInstance(document, new
FileOutputStream("Chap0101.pdf"));
System.out.println("koko2");

// step 3: we open the document
document.open();
System.out.println("koko3");
// step 4: we add a paragraph to the document
document.add(new Paragraph("pravoooooo"));
System.out.println("koko4");

}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}

// step 5: we close the document
document.close();
System.out.println("koko5");
}
}

that code run successfully on a java file while it doesn't on the servlet
here's the hole project source code
ads.osdn.com/\
ions=1,2
we'll need 2 files
1- itext-1.02.jar 749k
2- itext-xml-1.02.jar 23k

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Failed to load target servlet Or get search suggestion and latest updates.




Tagged: