Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JSP
Problem with File Upload
Leonid Dukhvalov
Greenhorn
Posts: 1
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I'm trying to use the Apache Commons FileUpload, however every time it returns an empty list. This is my code:
---UploadFiles.html--- <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/> <TITLE>File Upload Page</TITLE> </HEAD> <BODY>Upload Files <FORM name="filesForm" action="ProcessFileUpload.jsp" method="post" enctype="multipart/form-data"> File 1:<input type="file" name="file1"/><br/> File 2:<input type="file" name="file2"/><br/> File 3:<input type="file" name="file3"/><br/> Text 3:<input type="text" name="text1"/><br/> <input type="submit" name="Submit" value="Upload Files"/> </FORM> </BODY> </HTML>
---ProcessFileUpload.jsp--- <%@ 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.*"%> <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()+"<br>"); DiskFileUpload fu = new DiskFileUpload(); // If file size exceeds, a FileUploadException will be thrown fu.setSizeMax(1000000); List fileItems = fu.parseRequest(request); Iterator itr = fileItems.iterator(); out.println("List size: " + fileItems.size()+"<br>"); 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()+"<br>"); out.println("SIZE: "+fi.getSize()+"<br>"); File fNew= new File(application.getRealPath("/"), fi.getName()); fi.write(fNew); } else { out.println("Field ="+fi.getFieldName()+"<br>"); } } %> </body> </html>
The result is:
Content Type =multipart/form-data; boundary=---------------------------7d42552e8b007e List size: 0
What am I doing wrong? I am using
Tomcat
5.0 right now, but I had the same problem with Tomcat 4.1.
Pedro Gongora
Greenhorn
Posts: 17
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi, your code is perfectly right, i've copy & pasted it on my machine and worked fine.
which browser are you using?
do you have any proxy, load balancer, web server, etc. in front of your tomcat??
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Upload files from client
problem with commons FileUpload
Jakarta FileUpload
File Upload Error
Setting File Permissions
More...