Results 1 to 3 of 3
Thread: Simple upload servlet
- 01-28-2011, 06:07 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 18
- Rep Power
- 0
Simple upload servlet
Hi
I haven't been writing servlets for very long. I tried using the "org.apache.commons.fileupload" package but couldn't really get it to work. It would bomb at run-time. But at the same time, I think it is overkill for a simple file upload.
Is there a simpler way to upload a file to spot on my web server? I am trying to upload PDFs. Just a simple one file upload. Or should I just go back and figure out why "fileupload" is not working?
If curious the error is:
java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileUploadException
Thanks!
- 01-28-2011, 08:45 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 18
- Rep Power
- 0
Hi
Apparently, **AGAIN**, it does not work in Eclipse. But had to add commons-io.jar to Tomcat which they should have included in the download.
Now my problem is that I took the code from Apache and it is uploading the files but the printout shows that it is looping only once in the iteration:
And my output looks like this:Java Code:while(itr.hasNext()) { out.println( "Pass into loop" ); FileItem item = (FileItem) itr.next(); /* * Handle Form Fields. */ if(item.isFormField()) { out.println("Form field" ); out.println("File Name = "+item.getFieldName()+", Value = "+item.getString()); } else { //Handle Uploaded files. out.println("upload the files" ); out.println("Field Name = "+item.getFieldName() ); out.println("File Name = "+item.getName() ); out.println("Content type = "+item.getContentType() ); out.println("File Size = "+item.getSize() ); out.println( ); /* * Write file to the ultimate location. */ File file = new File(destinationDir,item.getName()); item.write(file); } //end if else out.close(); } //end while
Java Code:<h1>Servlet File Upload Example using Commons File Upload</h1> Pass into loop upload the files Field Name = fileggg1 File Name = g.jpg Content type = image/jpeg File Size = 2548
So, it uploads 3 files but will only show the first filename. How can I get it to show all the uploaded files?
Thanks!
- 01-29-2011, 08:43 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
How to upload image in jsp/servlet
By ibhaviik in forum Java ServletReplies: 11Last Post: 11-16-2010, 11:32 AM -
Ajax / servlet File upload
By n3mesi83 in forum Java ServletReplies: 0Last Post: 06-08-2010, 02:48 PM -
upload and download file using servlet
By amit_m04 in forum Java ServletReplies: 1Last Post: 09-27-2009, 03:06 AM -
File Upload Servlet problem
By jeniramires in forum Advanced JavaReplies: 3Last Post: 08-18-2008, 07:34 PM -
how to upload a file using servlet
By simon in forum Java ServletReplies: 1Last Post: 08-05-2007, 03:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks