What's the problem of uploading file in this code

hi,

i have written following code for uploading a an image file. But when i run this pogram in Eclipse3.1.2 then it shows following Error:

I have written following file for selecting a file

<body>

<form action="display.jsp" method="POST" enctype="multipart/form-data">

<input type="file" name="File1">

<input type="submit" name ="button" >

</form>

</body>

display.jsp file contain the following code:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

<%@page import="org.apache.commons.fileupload.*" %>

<%@page import="java.io.*" %>

<%@page import="java.util.*" %>

</head>

<body>

File uploaded

<%

boolean isMulti = FileUpload.isMultipartContent(request);

DiskFileUpload upload=new DiskFileUpload();

List items=upload.parseRequest(request);

Iterator iter=items.iterator();

while(iter.hasNext()){

FileItem item=(FileItem)iter.next();

if(item.isFormField()){

String name=item.getFieldName();

String value=item.getString();

%>

<%=name%>

<%=value %>

<%}else{

InputStream stream=item.getInputStream();

OutputStream os=new FileOutputStream("d:/image.jpg");

int bytesRead = 0;

byte[] buffer =newbyte[8192];

while ((bytesRead = stream.read(buffer, 0, 8192)) != -1){

os.write(buffer, 0, bytesRead);

}

os.close();

stream.close();

item.delete();

}

}

%>

</body>

</html>

Error is:

org.apache.jasper.JasperException: Exception in JSP: /display.jsp:19

16:

17:boolean isMulti = FileUpload.isMultipartContent(request);

18: DiskFileUpload upload=new DiskFileUpload();

19: List items=upload.parseRequest(request);

20: Iterator iter=items.iterator();

21:

22:while(iter.hasNext()){

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: org/apache/commons/io/output/DeferredFileOutputStream

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)

org.apache.jsp.display_jsp._jspService(display_jsp.java:103)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

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

org.apache.commons.fileupload.DefaultFileItemFactory.createItem(DefaultFileItemFactory.java:102)

org.apache.commons.fileupload.FileUploadBase.createItem(FileUploadBase.java:500)

org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)

org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:268)

org.apache.jsp.display_jsp._jspService(display_jsp.java:62)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Is there anybody can help me? Why this code is not working. I have used Tomcat5.5 for the server. Please help me

With regards

Bina

[5548 byte] By [bina_jatnoa] at [2007-10-2 23:02:11]
# 1

You should have commons-fileupload.jar in common/lib or in ur applications lib directory( I mean WEB-INF/lib). Dont forget to set the build path to commons-fileupload.jar in Eclipse.

Go to

project > properties > Java Build Path > libraries > click on Add External Jars button > choose ur commons-fileupload.jar file > click on OK

siva_forumsa at 2007-7-14 6:16:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
hi,I have already have done all the things what u have said. Further that i see this error. Can u give me solution ? What's the problem of my code? Can u give me a correct code? Please help me.With regardsbina
bina_jatnoa at 2007-7-14 6:16:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
where u have placed ur commons-fileupload.jar file?..put it in ur applicationsWEB-INF/lib .Bcoz i tried out ur example code. Its working fine. i had placed jar file in above said location
siva_forumsa at 2007-7-14 6:16:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hi,

i have kept commons.fileupload1.1.1.jar in my apllications /webContent/WeB-INF/LIB/Directory. & i have also added this jar with the eclipse by project Properties->Build-Path->Library-> Add External jar. /further that my code shows the same error. Now what will i do?

Please help me

With Regards

Bina

bina_jatnoa at 2007-7-14 6:16:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...