troubleshooting Question

Need help compiling commons fileupload

Avatar of Mark
Mark asked on
JavaJSP
11 Comments1 Solution1931 ViewsLast Modified:
I'm struggling to get a fileupload program working. My code is attached below. I've taken most of it right from the Apache commons file upload 1.2.1 documentation. Below is the error I'm getting. What am I missing?

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 10 in the jsp file: /testing/fileuploaddemo.jsp
DiskFileItemFactory cannot be resolved to a type
7: boolean isMultipart = FileUpload.isMultipartContent(request);
8:
9: // Create a factory for disk-based file items
10: DiskFileItemFactory factory = new DiskFileItemFactory();
11:
12: // Create a new file upload handler
13: ServletFileUpload upload = new ServletFileUpload(factory);

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<%@ page contentType="text/html; charset=ISO-8859-1" %>
<%@ page import="org.apache.commons.fileupload.*"%>
<html>
<body>
<%
boolean isMultipart = FileUpload.isMultipartContent(request);
 
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
 
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
 
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
 
// Process the uploaded items
Iterator iter = items.iterator();
 
while (iter.hasNext())
{
    FileItem item = (FileItem) iter.next();
 
    if (item.isFormField())
    {
        out.println("<br>name:  " + item.getFieldName());
        out.println("<br>value: " + value = item.getString());
    }
    else {
        out.println("<br>file field name: " + item.getFieldName());
        out.println("<br>file name: " + item.getName());
        out.println("<br>contentType: " + item.getContentType();
        out.println("<br>isInMemory: " + item.isInMemory());
        out.println("<br>File size: " + = item.getSize());
    }
}
 
%>
<%=isMultipart%>
 
</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros