title: File upload problem using Apache commans File upload API in JSP/Servlet
body: <p>im trying to upload a file using org.apache.commons.fileupload. but i dont no, what mistake i have made im getting the following error in my servlet. please any one help me on this..this is the error im getting.</p>
  
  <pre><code>     javax.servlet.ServletException: Servlet execution threw an exception
  
  
   root cause 
  
   java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
  org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)
  org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361)
  org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
  upload1.doPost(upload1.java:34)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </code></pre>
  
  <p>this is my servlet code</p>
  
  <pre><code>   if (ServletFileUpload.isMultipartContent(req)) {
  
           // 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&lt;FileItem&gt; items = upload.parseRequest(req);
               for (FileItem item : items) {
                   // process only file upload - discard other form item types
                   if (item.isFormField()) continue;
  
                   String fileName = item.getName();
                   // get only the file name not whole path
                   if (fileName != null) {
                      // fileName = FilenameUtils. getName(fileName);
                   }
  
  
               }
           } catch (Exception e) {
               res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                       "An error occurred while creating the file : " + e.getMessage());
           }
  
       } else {
           res.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                           "Request contents type is not supported by the servlet.");
       }
  </code></pre>
  
  <p>and form   </p>
  
  <pre><code>          &lt;form method="POST" action="upload1" enctype="multipart/form-data" &gt;
  </code></pre>
  
  <p>thank u</p>