Problem with commons.fileupload

I'm using Tomcat 4.1 and before I couldn't get the compiler to find the package until I put it in my %JAVA-HOME%\jre\lib\ext folder. After I did that I could compile just fine. Now when I try uploading a file I get 'NoClassDefFoundError'. I read that this is because I have the jar file in both the %JAVA-HOME% and WEB-INF\lib . I tried running it without having it in %JAVA-HOME% and it made no difference. If anyone can help I would really appreciate it. Thanks.

I suggest taking a look at the user guide, they do some things differently than you do:
http://jakarta.apache.org/commons/fileupload/using.html

Similar Messages

  • Problem with Commons FileUpload and ssl

    Hi,
    i want to send to servlet mulipart form data using ssl:
    this is my html page:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>simple form page</title>
        </head>
        <body>
            <form method="POST" enctype="multipart/form-data" action="SimpleResponseServlet">
                <br><input type=file name=upfile></input></br>
                <br><input type=text name=note></input></br>
                <br><input type=submit value=Press></input></br>
             </form>
         </body>
    </html>This is code from SimpleResponseServlet:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
       response.setContentType("text/plain;");
       PrintWriter out = response.getWriter();
       boolean isMultipart = ServletFileUpload.isMultipartContent(request);
       System.err.println(isMultipart);
       try{
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                List items = upload.parseRequest(request);
             Iterator iter = items.iterator();
                while(iter.hasNext())
                     FileItem item = (FileItem) iter.next();
                     System.out.println(item.getContentType());
                     System.out.println(item.getFieldName());
                     System.out.println(item.getName());
                     System.out.println(item.isFormField());
           out.println("ok");
      catch(Exception ex){
       System.out.println(ex.toString());
      finally{ 
        out.close();
            this is what Tomcat 6.0 console show using https to call servlet:
    false
    org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException:the request doesn't contain a multipart/form-data or multipart/mixed-stream, content type header is null.if i use normal http servlet works fine.
    Help me, please.
    Thank you,
    David.

    I have replaced in html page this attribute:
    action="SimpleResponseServlet"with this:
    action="https://localhost:8443/ProvaImageReaderServlet/SimpleResponseServlet"and servlet can read items because there's not redirecting.
    But is it a clear way call directly servlet with https???
    Thank you....

  • Problem with commons-fileupload library.

    Hello,
    I'm using the following code to try and upload files to my Tomcat server from HTTP clients. The code is inside a JSP page. When I submit the form to this jsp page, I get no errors but the file is not being uploaded and the only out.println statement that is printing is the first one that tests if the form is multi-part. It prints true.
         boolean isMultipart = FileUpload.isMultipartContent(request);
         out.println("" + isMultipart);
         if (isMultipart) {
              DiskFileUpload upload = new DiskFileUpload();
              upload.setSizeThreshold(2000000);
              upload.setSizeMax(5000000);
              int sizeThresh = 2000000, sizeMax = 5000000;
              String dir = "c:/temp";
              List items = upload.parseRequest(request, sizeThresh, sizeMax, dir);
              Iterator iter = items.iterator();
              while (iter.hasNext()) {
                   FileItem item = (FileItem) iter.next();
                   out.println(item.getFieldName());
                   if (item.isFormField()) {
                        continue;
                   else {
                        String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        String contentType = item.getContentType();
                        boolean isInMemory = item.isInMemory();
                        long sizeInBytes = item.getSize();
                        out.println("Info: " + sizeInBytes + " " + contentType + " " + fileName + " " + fieldName);
                        File uploadedFile = new File("test.txt");
                        item.write(uploadedFile);
         } Any idea what my problem is?
    Thanks.

    Sorry to keep posting but this gets more complex. Here's the deal.
    The UploadBean works on both Tomcat 4 and Tomcat 5 as long as the code below has not been called yet for the user's session. It is code that asks the browser for authentication. Once this code has been called for the current session, the Upload Bean no longer works.
    Any idea what would cause this?
    package com.biscuit.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * NTLM authorization (Challenge-Response) test servlet.
    * Requires IE on the client side.
    * In order to avoid browser log on dialog box User Authentication/Logon
    * settings should be set to:
    * <ol>
    * <li>Automatic logon in Intranet zone or</li>
    * <li>Automatic logon with current username and password</li>
    * </ol>
    * Based on information found on jGuru WEB site:
    * http://www.jguru.com/faq/viewquestion.jsp?EID=393110
    * @author Leonidius
    * @version 1.0 2002/06/17
    public class NTLMTest extends HttpServlet{
         // Step 2: Challenge message
         final private static byte[] CHALLENGE_MESSAGE =
              {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S', (byte)'S', (byte)'P', 0,
              2, 0, 0, 0, 0, 0, 0, 0,
              40, 0, 0, 0, 1, (byte)130, 0, 0,
              0, 2, 2, 2, 0, 0, 0, 0, // nonce
              0, 0, 0, 0, 0, 0, 0, 0};
         * HTTP request processing
         protected synchronized void service(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException{
              PrintWriter out = response.getWriter();
              try{
                   String auth = request.getHeader("Authorization");
                   if (auth == null) {
                        response.setContentLength(0);
                        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                        response.setHeader("WWW-Authenticate", "NTLM");
                        response.flushBuffer();
                        return;
                   if (!auth.startsWith("NTLM ")) return;
                   byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
                   // Step 1: Negotiation message received
                   if (msg[8] == 1) {
                        // Send challenge message (Step 2)
                        response.setContentLength(2);
                        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                        response.setHeader("WWW-Authenticate",
                        "NTLM " + new sun.misc.BASE64Encoder().encodeBuffer(CHALLENGE_MESSAGE));
                        out.println(" ");
                        response.flushBuffer();
                        return;
                   // Step 3: Authentication message received
                   if (msg[8] == 3) {
                        int off = 30;
                        int length, offset;
                        length = (msg[off+1]<<8) + msg[off];
                        offset = (msg[off+3]<<8) + msg[off+2];
                        String domain = new String(msg, offset, length);
                        domain = removeBlanks(domain).toUpperCase();
                        length = (msg[off+9]<<8) + msg[off+8];
                        offset = (msg[off+11]<<8) + msg[off+10];
                        String user = new String(msg, offset, length);
                        user = domain + "\\" + removeBlanks(user).toUpperCase();
                        HttpSession session = request.getSession(true);                    
                        session.setAttribute("userID", user);                    
                        String forwardAddress = "home";     
                        RequestDispatcher dispatcher = request.getRequestDispatcher(forwardAddress);
                        dispatcher.forward(request, response);
    //                    length = (msg[off+17]<<8) + msg[off+16];
    //                    offset = (msg[off+19]<<8) + msg[off+18];
    //                    String ws = new String(msg, offset, length);
    //                    ws = removeBlanks(ws);
    //                    response.setContentType("text/html");
    //                    out.println("<html>");
    //                    out.println("<head>");
    //                    out.println("<title>NT User Login Info</title>");
    //                    out.println("</head>");
    //                    out.println("<body>");
    //                    out.println(new java.util.Date() + "<br>");
    //                    out.println("Server: " + request.getServerName() + "<br><br>");
    //                    out.println("Domain: " + removeBlanks(domain) + "<br>");
    //                    out.println("Username: " + removeBlanks(user) + "<br>");
    //                    out.println("Workstation: " + removeBlanks(ws) + "<br>");
    //                    out.println("</body>");
    //                    out.println("</html>");
              catch (Throwable ex){
                   ex.printStackTrace();
         }//service
         * Removes non-printable characters from a string
         private synchronized String removeBlanks(String s){
              StringBuffer sb = new StringBuffer();
              for (int i = 0; i < s.length(); i++) {
                   char c = s.charAt(i);
                   if (c > ' ')
                   sb.append(c);
              return sb.toString();
    }//class NTLMTest

  • J2ee.jar causes problems with commons-logging.jar

    Hi All -
    (JDK 1.5.0_03, commons-logging 1.0.4, latest j2ee.jar, Eclipse 3.1.0 RC3 )
    I am developing some components that are to be used within j2ee containers and in standalone mode as well. When I run the software under Tomcat, it works correctly (Tomcat is not using the j2ee.jar that comes with Sun's App server obviously), but when I develop with the j2ee.jar file that comes with Sun's App server, I can't use commons-logging. For example, the code supplied below (a class with only this line in the main method, not using any j2ee features) will fail JUST by having j2ee.jar in my path, but if I take it out of the path, it works fine. I am also on the commons-logging mail list and no one there has been able to solve this issue for me. Again, if I deploy my application to Tomcat, I don't have this problem.
    The isolated line that is giving me the issue (and will give the issue even in a non j2ee application that just has this one line) is this:
    log= LogFactory.getLog(CommonsLoggingTest.class);
    When I run this without j2ee.jar in the path, it works fine. When I run it with j2ee.jar in the path, I get this:
    Exception in thread "main" org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
         at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
         at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
         at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
         at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
         at com.redhawk.testing.CommonsLoggingTest.doTest(CommonsLoggingTest.java:27)
         at com.redhawk.testing.CommonsLoggingTest.main(CommonsLoggingTest.java:45)
    Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
         at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
         at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
         ... 5 more
    Caused by: java.lang.NullPointerException
         at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
         ... 6 more
    Anyone have any ideas? Its really annoying to have to take this jar file out of my path every time I want to run a test. I could just start developing against other implementations of the j2ee classes I need (for example, Tomcat's jar files do not give this error) but for various reasons that is also undesirable.
    Thanks!
    Jason

    This problem does not arise with commons-logging 1.0.3.
    Any idea what is different in 1.0.4 that would introduce problems when Sun's j2ee.jar is in the path?

  • Problem with hx:fileupload

    Hello!
    I have a new problem. I'm using a hx:fileupload tag, but when I write in this input text intead of selecting the browse button I get a javascript error. I have read that is a problem only with IE, so I need to make readonly this field.
    I have also read that a readonly is not easy for an input type file, I have found a solution here
    http://www.codeguru.com/forum/archive/index.php/t-197501.html
    but when I have tried the solution I find a new error, when I click over a submit file my hx:fileuploadis clear and a submit is not executed.
    I don�t know why my file is clear.
    Can someone help me again
    thanks

    Sorry, I have no solution for you but I do have the same problem. I have been searching every java site/forum I could found for a solution but no luck so far.
    As soon as the �DiskFileUpload upload = new DiskFileUpload()� line is executed the program crash with a NoClassDefFoundError: javax/servlet/ServletInputStream. There is no problem creating a ServletInputStream object though. I would also appreciate it very much if anyone could give us any ideas on what might cause this error.

  • Problems with htmlb:fileUpload

    Hi, I am trying to implement a JSPDynPage which uses the
    fileUpload-Tag. In most cases it works fine but sometimes I can select a file but the next button click (onWork) event is not send to the server.
      <hbj:form id="myForm" encodingType="multipart/form-data">
      <hbj:formLayoutCell id="cf_fimport_2" align="center"  valign="TOP" width="175">
         <hbj:fileUpload id="upload" size="30" accept="plain/text"/>
      </hbj:formLayoutCell>
    and the button is defined
    <hbj:formLayoutCell id="cf_fimport_5" align="right" paddingRight="7">
      <hbj:button id="bpreview" text='doWork' design="STANDARD" disabled="false"
    onClick="work"/>
    </hbj:formLayoutCell>
    The page is refreshed but no action is done.
    Any idea?
    Is there a bit more documentation about the fileUpload-Tag ?
    Environment:
    Windows XP
    SAP EP6 SP4 Sneak Preview
    IE 6.0
    Regards
    Edmund

    Dear Edmund.
    I've exactly the same problem.
    In details:
    Prerequisites:
    1) there is <hbj:fileUpload ...> tag on the jsp.
    2) The form is declared as <hbj:form id="....." encodingType="multipart/form-data">
    3) There is defined button with handled event e.g. "onButtonClicked"
    4) The user will insert any file to the tag
    Behavior:
    1) The request does NOT consist ANY components. ( I can see in the log )
    2) The method "onButtonClicked" is NOT called.
    3) Randomly - there is onInitialization() method called.
    As it was mentioned by You, the older versions of portal works with the hbj:fileUpload correctly.
    I will be very pleased with someone explaining the problem.
    Regards Best
    Marek
    P.S.Very interesting fact: when <the hbj:fileUpload> is empty the request is sent properly - with all the components.

  • Problem with common services discovery !

    hi, I have set the network discovery setting to use (arp-ospf, and cdp) . after the network discovery was finished I found out that there are 30 devices which had been discovered but in unreachable state !!!!
    I start to ping all those devices and hopfully all of them had good reply times, I wonder how is it posible that a device go to unreachable state as long as I have its ping reply ??
    thank you indeed

    Discovery does more than simply ping devices.  In order for a device to be reachable, Discovery must be able to communicate with the device via SNMP.  Take a look at this document for more on how Discovery works:
    https://supportforums.cisco.com/docs/DOC-9005

  • Commons.fileupload not working

    i want to upolad file with commons.fileupload lib
    it doesnt get the file name
    it doesnt even get through the iteration ?
    if (ServletFileUpload.isMultipartContent(request)){
      ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
      List items = servletFileUpload.parseRequest(request);
      Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (!item.isFormField()) {
                fileName = item.getName();
                fileName = FilenameUtils.getName(fileName);
                out.println("fileName"+fileName);
                File saveTo = new File(filesSavePath + fileName);
                try {
                     item.write(saveTo);
                catch (Exception ex){
                out.println("Plik nie zosta³ zapisany.");
                ex.printStackTrace();
    }thank You

    did you turn your form into a multipart form?
    <form method="post" enctype="multipart/form-data">

  • Problems with Apache Commons FileUpload

    I'm completely stymied here. I've been trying to get the Apache Commons FileUpload working with a JBoss 4.2 server, and having no luck whatsoever. The servlet is listed out here:
    package com.areteinc.servlets;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileItemFactory;
    import org.apache.commons.fileupload.FileUploadException;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    public class Filer extends HttpServlet {
         private Logger logger = Logger.getLogger(Filer.class);
         public Filer() {
              logger.setLevel(Level.DEBUG);
         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              logger.debug("Serving up a GET page...");
              PrintWriter writer = resp.getWriter();
              StringBuffer response = new StringBuffer();
              response.append("<HTML><HEAD><TITLE>JENA File Uploader</TITLE></HEAD><BODY>");
              response.append("<FORM action=\"Filer\" method=\"POST\" enctype=\"multipart/form-data\">");
              response.append("Upload file: <input type=\"file\" name=\"file1\"/><br>");
              response.append("Upload file: <input type=\"file\" name=\"file2\"/><br>");
              response.append("<input type=submit value=\"Start upload\">");
              response.append("</BODY>");
              writer.println(response);
         protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              // First see if someone is uploading more than one file at a time...
              boolean isMultipart = ServletFileUpload.isMultipartContent(req);
              logger.debug("Received a POST request.  Multipart is flagged as " + isMultipart);
              // Create a factory for disk-based file items
              FileItemFactory factory = new DiskFileItemFactory();
              // Create a new file upload handler
              ServletFileUpload upload = new ServletFileUpload(factory);
              // Parse the request
              try {
                   List<FileItem> items = upload.parseRequest(req);
                   Iterator itr = items.iterator();
                   logger.debug("Size of upload is " + items.size() + " items.");
                   while(itr.hasNext()) {
                        FileItem item = (FileItem) itr.next();
                        logger.debug("Filename is " + item.getName());
              } catch (FileUploadException e) {
                   e.printStackTrace();
    }When run, I hit it with a get operation, and get the form. When I put in 2 forms (in reality, all i want to do is use one, but I'm tinkering), I see nothing in items list...
    Run, with 2 files selected to upload:
    13:50:15,421 DEBUG [Filer] Received a POST request. Multipart is flagged as true
    13:50:15,421 DEBUG [Filer] Size of upload is 0 items.
    I've tried variation after variation after variation, and it jst doesn't work. I'm using commons-fileupload-1.2.1.
    Help! :)

    On the client side, the client's browser must support form-based upload. Most modern browsers do, but there's no guarantee. For your case,
    The servlet can use the GET method parameters to decide what to do with the upload while the POST body of the request contains the file data to parse.
    When the user clicks the "Upload" button, the client browser locates the local file and sends it using HTTP POST, encoded using the MIME-type multipart/form-data. When it reaches your servlet, your servlet must process the POST data in order to extract the encoded file. You can learn all about this format in RFC 1867.
    Unfortunately, there is no method in the Servlet API to do this. Fortunately, there are a number of libraries available that do. Some of these assume that you will be writing the file to disk; others return the data as an InputStream.
    Jason Hunter's MultipartRequest (available from [http://www.servlets.com/])
    Apache Jakarta Commons Upload (package org.apache.commons.upload) "makes it easy to add robust, high-performance, file upload capability to your servlets and web applications"
    *CParseRFC1867 (available from [http://www.servletcentral.com/]).
    *HttpMultiPartParser by Anil Hemrajani, at the isavvix Code Exchange
    *There is a multipart/form parser availailable from Anders Kristensen ([http://www-uk.hpl.hp.com/people/ak/java/] at [http://www-uk.hpl.hp.com/people/ak/java/#utils].
    *JavaMail also has MIME-parsing routines (see the Purple Servlet References).
    *Jun Inamori has written a class called org.apache.tomcat.request.ParseMime which is available in the Tomcat CVS tree.
    *JSPSmart has a free set of JSP for doing file upload and download.
    *UploadBean by JavaZoom claims to handle most of the hassle of uploading for you, including writing to disk or memory.
    There's an Upload Tag in dotJ
    Once you process the form-data stream into the uploaded file, you can then either write it to disk, write it to a database, or process it as an InputStream, depending on your needs. See How can I access or create a file or folder in the current directory from inside a servlet? and other questions in the Servlets:Files Topic for information on writing files from a Servlet.
    Please note: that you can't access a file on the client system directly from a servlet; that would be a huge security hole. You have to ask the user for permission, and currently form-based upload is the only way to do that.
    I still have doubt if all the moentioned resources are alive or not

  • Commons fileupload problem with Jdeveloper

    Hi,
    I tried to use commons fileupload with jdeveloper and I have put those two jar files under web-inf/lib directory. but it did not work. Anyone can help? Thanks in advance. Error code is shown below:
    Error(79,33): illegal start of expressionError: cannot access class org.apache.commons.fileupload.FileItem; file org\apache\commons\fileupload\FileItem.class not found
    Error: cannot access class org.apache.commons.fileupload.FileItemFactory ; file org\apache\commons\fileupload\FileItemFactory.class not found
    Error: cannot access class org.apache.commons.fileupload.FileUpload; file org\apache\commons\fileupload\FileUpload.class not found
    Error: cannot access class org.apache.commons.fileupload.disk.DiskFileItemFactory ; file org\apache\commons\fileupload\disk\DiskFileItemFactory.class not found
    Error: cannot access class org.apache.commons.fileupload.servlet.ServletFileUpload; file org\apache\commons\fileupload\servlet\ServletFileUpload.class not found
    Error: cannot access class org.apache.commons.fileupload.FileUploadBase; file org\apache\commons\fileupload\FileUploadBase.class not found
    Error: cannot access class org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; fileorg\apache\commons\fileupload\FileUploadBase\SizeLimitExceededException.class not found
    Error(25,29): variable ServletFileUpload not found in class _upload
    Error(31,7): class DiskFileItemFactory not found in class _upload
    Error(31,41): class DiskFileItemFactory not found in class _upload
    Error(43,7): class ServletFileUpload not found in class _upload
    Error(43,38): class ServletFileUpload not found in class _upload
    Error(52,15): class SizeLimitExceededException not found in class _upload
    Error(61,7): class FileItem not found in class _upload
    Error(61,24): class FileItem not found in class _upload                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Are you sure you have the full JDK or just JRE?
    Check the size of the jar you downloaded to make sure it downloaded complete.
    Basic install instructions are here:
    http://download.oracle.com/docs/cd/E14571_01/install.1111/e13666/ojdig.htm#BDCJDDFE

  • Attachements with apache commons fileupload

    I'm using:
    http://commons.apache.org/fileupload/
    to write file on server side (Tomcat running on Windows with XP or 2003).
    I'm sending data to servlet with doPost() as follows:
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(4096);
                factory.setRepository(new File("test"));
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(1000000);
                List fileItems = upload.parseRequest(request);
                Iterator i = fileItems.iterator();
                String comment = ((FileItem) i.next()).getString();
                FileItem fi = (FileItem) i.next();
                String fileName = fi.getName();
                // db
                fi.write(new File("C:/", fileName));
            } catch (Exception ex) {
                out.print(ex.getMessage());
            out.close();
        }but it's response is:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet execution threw an exception
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
    Apache Tomcat/6.0.16don't know why.. any ideas?

    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStreamThe mentioned class is missing in the runtime classpath.
    Add it (in this specific case, the JAR file with the mentioned class) to the classpath and the problem will disappear.
    This class is part of Commons IO. Read the dependencies page at FileUpload user guide which JAR's you all need.

  • File size with Jakarta Commons FileUpload

    Hello fella experts,
    I am using the org.apache.commons.FileUpload package to upload a file via a servlet.
    I'm implementing the DiskFileUpload() method in the servlet.
    My problem is that I want to apply a file-size validation and specify that files with size greater than 1MB should not be uploaded.
    How to accomplish this ?
    Any suggessions ?
    Thanx in advance.

    Hi, I'm trying this code, and it works pretty fine, but when I try to transfer a .zip file, it give me a .zip file that I can't extract.
    Please.. Am I doing something wrong, do I miss something??
    I set already the File Type to binary...
    any comments..
    public static void copyFiles(String server, String user, String pwd, String origen, String destino)
    try {
    FTPClient ftp = new FTPClient();
    ftp.connect(server);
    ftp.login(user,pwd);
    ftp.setFileType(ftp.BINARY_FILE_TYPE);     
    //ftp.enterLocalPassiveMode();
    ftp.changeWorkingDirectory(origen);
    int reply = ftp.getReplyCode();
    if(!FTPReply.isPositiveCompletion(reply)) {
    ftp.disconnect();
    FTPFile[] files = ftp.listFiles();
    FTPFile ftpfile = null;
    OutputStream output = null;
    for (int i = 0; i < files.length; i++) {
    ftpfile = files;
    if (ftpfile.isFile()){
    output = new FileOutputStream(new File(destino+ftpfile.getName()));
    if (ftp.retrieveFile(ftpfile.getName(),output)){
    output.close();
    ftp.logout();
    ftp.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("Error : " + e.toString());

  • File upload using apache Commons FileUpload problem

    Hi All,
    I have used Commons FileUpload for uploading files from windows to unix machine. I'm able to upload files but I have a problem about the contents of file copied in unix. When i upload files few files containing special characters are not copied correctly in unix instead ascii codes are getting copied/written. Seems to be a problem with character encoding.
    For example symbol "�" is not getting copied correctly in unix. So as new line character to. If anyone has faced such issues kindly provide few pointers on this. Appreciate your guidance.
    Thanks,
    -Aj

    Thanks for the reply.
    I'm using the Commons FileUpload class "FileItem" which holds the filestream data and using function
    code snippet of file upload
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    Iterator it = fileItemsList.iterator();
    while (it.hasNext())
         FileItem fileItemTemp = (FileItem)it.next();
         File saveToFile = new File("newFile");
          fileItem.write(saveToFile ); // write fileItem data to saveToFile.
    } FileItem object takes care of writing data to disk.No idea,how it does internally.
    Thanks,
    -Aj.

  • Jakarta Commons FileUpload ; Internet Explorer Problem

    Hi all,
    Environment:
    Tomcat 5 ;Apache 2; JDK 1.5.0; Jakarta Commons Fileupload 1.0
    OS: Windoze XP
    Previously I've used jakarta commons fileupload package to succussfully to upload a file.
    However, I am trying to check the content type of the file and throw an exception if its not a jpeg file. The following code works great when I use firefox. But it fails when I use Internet Explorer!
    When I supply an existing jpg file on my desktop as the input to the HTML form, the code works fine. However if I enter a non-existing jpg filename, I get a "HTTP 500 Internal Server Error"! I expect to get the "Wrong content type!" message (which my JSP throws as an exception and should be caught by the error page). This problem happens only with Internet Explorer. With firefox, I get the "Wrong Content Type" message as expected.
    What could be the problem? Please advise.
    Thanks
    Joe.
    Code follows......
    /************** file-upload.html *************/
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>File Upload</title>
    <script type="text/javascript" language="JavaScript">
    <!--
    function fileTypeCheck() {
         var fileName = document.uploadForm.pic.value;
         if (fileName == "") {
              alert ("Please select a file to upload!");
              return false;
         var indexOfExt = fileName.lastIndexOf (".");
         if (indexOfExt < 0) {
              alert('You can only upload a .jpg/.jpeg/.gif file!');
              return false;
         var ext = fileName.substring(indexOfExt);
         ext = ext.toLowerCase();
         if (ext != '.jpg' && ext != 'jpeg') {
             alert('You selected a ' + ext + ' file;  Please select a .jpg/.jpeg file instead!');
              return false;
         return true;
    //--></script>
    </head>
    <form action="uploadPhoto.jsp" enctype="multipart/form-data" method="post" name="uploadForm" onSubmit="return fileTypeCheck();">
         <input type="file" accept="image/jpeg,image/gif" name="pic" size="50" />
         <br />
         <input type="submit" value="Send" />
    </form>
    <body>
    </body>
    </html>
    /*************** photoUpload.jsp **************/
    <%@ page language="java" session="false" import="org.apache.commons.fileupload.*, java.util.*" isErrorPage="false" errorPage="uploadPhotoError.jsp" %>
    <%!
    public void processUploadedFile(FileItem item, ServletResponse response) throws Exception {
         try {
              // Process a file upload
                  String contentType = item.getContentType();
              if (! contentType.equals("image/jpeg") && ! contentType.equals("image/pjpeg")) {
                   throw new FileUploadException("Wrong content type!");
         } catch (Exception ex) {
              throw ex;
    %>
    <%
    // Check that we have a file upload requeste
    boolean isMultipart = FileUpload.isMultipartContent(request);
    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();
    // Parse the request
    List /* FileItem */ items = upload.parseRequest(request);
    // Process the uploaded items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (! item.isFormField()) {
            processUploadedFile(item, response);
    %>
    <html>
    <head>
    </head>
    <body>
    File uploaded succesfully! Thank you!
    </body>
    </html>
    /******** uploadPhotoError.jsp ****/
    <%@ page language="java" session="false" isErrorPage="true" %>
    <html>
    <head>
    </head>
    <body>
    <%
    out.println(exception.getMessage());
    %>
    </body>
    </html>

    I just found out that the problem that I have mentioned in my previous post has nothing to do with Jakarta Commons Fileupload. It happens whenever I try throwing an exception. And it happens only when I use Internet Explorer
    Thanks,
    Joe
    See the code below...
    /**** throw-error.jsp ***/
    <%@ page language="java" session="false" isErrorPage="false" errorPage="catch-error.jsp" %>
    <%
    throw new Exception("Catch this!");
    %>
    /****** catch-error.jsp ****/
    <%@ page language="java" session="false" isErrorPage="true" %>
    <html>
    <head>
    </head>
    <body>
    <%
    out.println(exception.getMessage());
    %>
    </body>

  • PROBLEM IN INTERNET EXPLORER WITH THE  fileupload API

    i written a servlet to upload a file which will upload a file to a specific directory..............
    this program is working with opera or Mozilla browser.......but it is not working in internet explorer 8.
    i can not understand what is the problem..............
    code working with opera or Mozilla and also for other browser but not with explorer 8..
    my code is
    index.jsp is a welcome file which is used to select a file  which i want to upload
    index.jsp
    <html>
    <head><title>Upload page</title></head></p> <p><body>
    <form action="uploadFile" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <center>
    <table border="2">
    <tr>
         <td align="center"><b>Multipale file Uploade</td>
         </tr>
    <tr>
         <td>
              Specify file: <input name="file" type="file" id="file">
         <td>     </tr>
         <tr>
         <td>
    <div align="center">
    <input type="submit" name="Submit" value="Submit files"/>
    </div></td>
    </table>
         <center>
    <p>
         </p>
    </form>
    </body>
    </html>
    uploadFile.java is servlet file which is used to upload the file in the specific location....
    the code of uploadFile.java is
    uploadFile.java
    import java.io.IOException;
    import java.util.Iterator;
    import java.lang.Object;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.List;
    import java.io.*;
    import java.io.File;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory ;
    import org.apache.commons.fileupload.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class uploadFile extends HttpServlet
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws IOException,ServletException {
    HttpSession session=request.getSession();
    PrintWriter out=response.getWriter();
    ServletConfig config=getServletConfig();
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if(!isMultipart)
    else
         FileItemFactory factory = new DiskFileItemFactory();
         ServletFileUpload upload = new ServletFileUpload(factory);
         List items = null;
         try {
              items = upload.parseRequest(request);
         } catch (FileUploadException e) {
              e.printStackTrace();
         Iterator itr = items.iterator();
         while (itr.hasNext()) {
         FileItem item = (FileItem) itr.next();
         if (item.isFormField()) {
         } else {
              try {
                   String itemName = item.getName();
                   if(itemName.equals(""))
                   session.setAttribute("itemName",itemName);
                   response.sendRedirect("index.jsp");
                   File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadedFiles/"+itemName);
                   item.write(savedFile);
                   out.println("Your file has been saved at the loaction:"+"\n"+config.getServletContext().getRealPath("/")+"uploadedFiles"+"\\"+itemName);
              } catch (Exception e) {
                   e.printStackTrace();
    Now i want to solve my problem in my code...............
    pleasde help me.............

    First of all, please do not shout in topic titles. It is rude.
    Secondly, please buy a new keyboard. Your dot key hangs all the time, it reads annoying.
    Back to your problem: did you read the FAQ available at the [FileUpload homepage|http://commons.apache.org/fileupload]? There´s something stated about a misbehaviour in IE and how to fix it using Commons IO. It is namely sending the complete client´s file path instead of only the file name.

Maybe you are looking for

  • Usage decision follow up action change of status in equipment

    Hello every one, I am having calibration scenerio in my project. All process is running properly but the issue which i am having is that when i am giving usage decision i should get a pop up to change the status of the equipment which is not coming i

  • Mac OS error -50

    I am trying to retrieve some QuickTime movies from my freespace.virgin.net. If I download using Fetch, the downloaded movie will not open and I get a "Mac OS error -50" message. If I try to open the movie directly at the server, Safari crashes. The o

  • How to make an checkbox editable and uneditable within a single alv output.

    Hi, How to make an checkbox editable and uneditable within a single alv output depending on condition. I have used Reuse_alv_grid_display. In my output every checkbox is editable. i have used edit = 'X'. I want editable checkbox for correct value and

  • The icloud backup didn't save all of my contacts

    I performed a manual icloud backup. After the backup completed, I checked my contact list online and it did not save half of my contacts. Any suggestions?

  • After Security update 2006-002, RAM is halved

    Hi, Right after applying the Security Update 2006-002, I experienced a freeze upon wake-up from sleep. And a general application slowdown. A fleeting look past the About this Mac window surprisingly revealed that the system now identifies the two add