Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

file upload problem

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please i need your help. I have configured Apache commons-fileupload.jar as shown below but when
I run the code, I recieved this error.

@echo off
echo Setting path for Java 1.6.0
echo Setting classpath for test servlets and Jsp
SET PATH=C:\Program Files\Java\jdk1.6.0\bin;%PATH%
SET CLASSPATH=.;C:\Tomcat 6.0\webapps\test\WEB-INF\classes;
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\lib\servlet-api.jar
SET CLASSPATH=%CLASSPATH%;C:\mysql-connector-java-5.0.4-bin.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\lib\mysql-connector-java-5.0.4-bin.jar
SET CLASSPATH=%CLASSPATH%;C:\Program Files\Java\jdk1.6.0\lib\mysql-connector-java-5.0.4-bin.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\webapps\form2\WEB-INF\lib\commons-fileupload-1.2.1.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\lib\commons-fileupload-1.2.1.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\lib\commons-fileupload-1.2.1-javadoc.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\lib\commons-fileupload-1.2.1-sources.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\webapps\form2\WEB-INF\lib\commons-fileupload-1.2.1-javadoc.jar
SET CLASSPATH=%CLASSPATH%;C:\Tomcat 6.0\webapps\form2\WEB-INF\lib\commons-fileupload-1.2.1-sources.jar

the error is this

HTTP Status 500 -


type Exception report


description The server encountered an internal error () that prevented it from fulfilling this request.


javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.

the code its self is this

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
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.*;

public class Upload extends HttpServlet {

* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PreparedStatement pst = null;
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {


conn = DriverManager.getConnection("jdbc:mysql://localhost/fredrick?user=root&password=root");
stmt = conn.createStatement();

FileUpload fup = new FileUpload();
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator iter = items.iterator();

int count = 0;
while (iter.hasNext()) {
FileItem item = (FileItem);
File cfile = new File(item.getName());
File tosave = new File(getServletContext().getRealPath("C:/Tomcat 6.0/webapps/form2/cow"), cfile.getName());
// String file_name = item.getName();
FileInputStream fis = new FileInputStream(tosave);
int len = (int) tosave.length();
pst = conn.prepareStatement("INSERT INTO test (image_data)values(?)");
//image_data column holds LONGBLOB data type

pst.setBinaryStream(1, fis, len);
int rows = pst.executeUpdate();

} catch (Exception e) {


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<form name="form_upload" action="Upload" method="POST" enctype="multipart/form-data">
<input type="file" name="image_data" value="" />
<input type="submit" value="Upload" />


Posts: 65785
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please edit your posts to add code tags, without which your code is illegible.
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Commons-fileupload has a dependency on commons-io, as the error message indicates.

But yes--please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

And welcome to JavaRanch!
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!