1 2 Previous Next 15 Replies Latest reply on Dec 17, 2004 4:15 AM by 843841

    upload file error, using com.oreilly.servlet.MultipartRequest

    843840
      I'm working on windows 2000 server with Tomcat4.0, and j2sdk1.4.0.

      servlet.jar and cos.jar are both located on d:\Tomcat4.0\common\lib and system's classpath.

      The code passed the compile, but got error on run time. I check the post here, but didn't found the resolution. Would anyone be able to help me? Thanks indeed!

      Code is:

      import java.io.*;
      import java.sql.*;
      import java.util.*;
      import java.text.*;
      import java.math.*;

      import javax.servlet.*;
      import javax.servlet.http.*;

      import com.oreilly.servlet.*;

      public class TemperDocServlet extends TemperBaseServlet
      {
      private Connection conTemper=null;
      private Statement stTemper=null;
      private StringBuffer sbTemperDoc = new StringBuffer();
      private String pageTitle="";
      private PrintWriter lout=null;

           private SimpleDateFormat formatter=new SimpleDateFormat("MM/dd/yyyy");

      protected void doGet (HttpServletRequest gareq, HttpServletResponse gares) throws ServletException, IOException
      {
           lout=gares.getWriter();
           gares.setContentType(" text/html");
           
           try {
                Class.forName(getJDBCClass());
                conTemper = DriverManager.getConnection(getDBURL(), getDBUser(), getDBPassword());
                createMain(gareq);
                if (stTemper!=null) stTemper.close();
                if (conTemper!=null) conTemper.close();
           } catch(Exception aException) { errorHandler(gares, lout, aException,aException.getMessage()); }
           }
           
      protected void doPost (HttpServletRequest pareq, HttpServletResponse pares) throws ServletException, IOException
      {
           lout=pares.getWriter();
           pares.setContentType(" text/html");
           
           try {
                Class.forName(getJDBCClass());
                conTemper = DriverManager.getConnection(getDBURL(), getDBUser(), getDBPassword());
                createMain(pareq);
                if (stTemper!=null) stTemper.close();
                if (conTemper!=null) conTemper.close();
           } catch(Exception aException) { errorHandler(pares, lout, aException,aException.getMessage()); }
           }
           
           private void createMain(HttpServletRequest areq) {
           try {
           String lLocalSaveDirectory = "D:\\InetPub\\wwwroot\\temper\\doc";
           MultipartRequest lMultipartRequest = new MultipartRequest(areq, lLocalSaveDirectory, 10*1024*1024); // 10MB
      if(lMultipartRequest.getParameter("submit").equals("Upload"))
      {
      sbTemperDoc.append("Files:");
      Enumeration lFile = lMultipartRequest.getFileNames();
      while (lFile.hasMoreElements()) {
           String name = (String)lFile.nextElement();
           String filename = lMultipartRequest.getFilesystemName(name);
           String type = lMultipartRequest.getContentType(name);
           File f = lMultipartRequest.getFile(name);
           FileReader fs = new FileReader(f);
           BufferedReader in = new BufferedReader(fs);
           String s, s2 = new String();
           while((s = in.readLine())!= null) s2 += s + "\n";
           //fileContent = s2;
           //session.setAttribute("fileContent", fileContent);
           //out.println(in.readLine());
           sbTemperDoc.append("name: " + name);
           sbTemperDoc.append("filename: " + filename);
           sbTemperDoc.append("type: " + type);
           if (f != null) {
           sbTemperDoc.append("f.toString(): " + f.toString());
           sbTemperDoc.append("f.getName(): " + f.getName());
           sbTemperDoc.append("f.exists(): " + f.exists());
           sbTemperDoc.append("f.length(): " + f.length());
           sbTemperDoc.append("fileContent: " + s2);
           }
           in.close();
      }
      }
      } catch (IOException e) { System.out.println("Error::"+e); }

      writeBody(lout, pageTitle, sbTemperDoc.toString(), writeLinkButton(""));
      sbTemperDoc.setLength(0);
      }
      }

      the error is:

      exception

      javax.servlet.ServletException: Servlet execution threw an exception
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

      .............

      root cause

      java.lang.NoClassDefFoundError: javax/servlet/ServletRequest
           at com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:222)
           at com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:109)
           at TemperDocServlet.createMain(TemperDocServlet.java:70)
           at TemperDocServlet.doPost(TemperDocServlet.java:61)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)



        1 2 Previous Next