aspose file tools*
The moose likes Servlets and the fly likes fileupload upon tomcat on local machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "fileupload upon tomcat on local machine" Watch "fileupload upon tomcat on local machine" New topic
Author

fileupload upon tomcat on local machine

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
mathew john
Greenhorn

Joined: Dec 14, 2004
Posts: 19
hi joseph ,

if You see the root cause it says no class Def error ,it looks like the server cannot find the class org/apache/commons/io/output/DeferredFileOutputStream.

Make sure that the Class DeferredFileOutputStream is present in the package
org/apache/commons/io/output under the /WEB-INF/classes folder in the web application.

If it is a jar file make sure it is present in the /WEB-INF/lib folder.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fileupload upon tomcat on local machine