File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Jakarta FileUpload on local machine Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Jakarta FileUpload on local machine Tomcat" Watch "Jakarta FileUpload on local machine Tomcat" New topic
Author

Jakarta FileUpload on local machine Tomcat

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Hi,
I am getting an exception when I am trying to upload a file by jakarta fileupload. I am working on Tomcat installed on my local machine. Yes I am trying to upload files to myself.

I appreciate your help.

here is the code:

upload_form.jsp
===============

<html><body>

<form name="myform" action="upload.jsp"
method="post" enctype="multipart/form-data">
Specify your name:<br />
<input type="text" name="name" size="15"/><br />
Specify your Image:<br />
<input type="file" name="myimage"><br/>
Specify your File:<br />
<input type="file" name="myfile"><br /><br />
<input type="submit" name="Submit" value="Submit your files"/>

</body></html>



upload.jsp
==========

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Process File Upload</title>
</head>
<body>
<%
out.println("Content Type ="+request.getContentType());

DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(5000000);

List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();

while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();

//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if(!fi.isFormField()) {
out.println("\nNAME: "+fi.getName());
out.println("SIZE: "+fi.getSize());
//System.out.println(fi.getOutputStream().toString());
out.println(fi.getFieldName());
File real = new File(fi.getFieldName());
//File fNew= new File(application.getRealPath("/temp/"), real.getName());
File fNew= new File(application.getRealPath("tempUpload/"), real.getName());

out.println(fNew.getAbsolutePath());
fi.write(fNew);
out.println("listo");
}
else {
out.println("Field ="+fi.getFieldName());
}
}
%>

Excelente archivo arriba!!
</body>
</html>


Exception
=========

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: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.upload_jsp._jspService(org.apache.jsp.upload_jsp:102)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
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:488)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:359)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:266)
org.apache.jsp.upload_jsp._jspService(org.apache.jsp.upload_jsp:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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


We must know, we will know. -- David Hilbert
Romain Devoiseau
Greenhorn

Joined: Mar 30, 2005
Posts: 1
You have to include the package commons-io from Jakarta in your classpath.

see:
http://jakarta.apache.org/site/downloads/downloads_commons-io.cgi

hope it helps

r-
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jakarta FileUpload on local machine Tomcat