Hi Manish,
I have to use the form bean. But I dont know how to write the form bean
for multiple file upload. In the jsp file I am using javascript to
generate the <input type="file"> dynamically. So it has the same name
attributes. I want to know how to get the values in each input types
while uloading. I am also using DiskFileUpload, but dont know how to
upload multiple files.
Thanks,
Dhanya
> Do you absolutely have to use a form bean?
>
[quoted text clipped - 10 lines]
> > Thanks in advance,
> > Dhanya
Matt Humphrey - 20 Sep 2006 12:10 GMT
> Hi Manish,
> I have to use the form bean. But I dont know how to write the form bean
[quoted text clipped - 3 lines]
> while uloading. I am also using DiskFileUpload, but dont know how to
> upload multiple files.
I'm probably way out of date (and I don't use jsp in any sophisticated way),
but I thought there was no such thing as multiple file upload. The HTML
<input ..> structure only accepts one file and there is no tag for multiple
files, regardless of whether it's generated by jsp or javascript or
whatever. Has that changed and does HTML have a multi-file upload now? Or
does the form bean generate something else?
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
Manish Pandit - 20 Sep 2006 21:19 GMT
Hi Matt,
Quite frankly - I tried multiple file upload once using the dyna action
beans (the ones you declare in struts-config.xml) and it never worked
out.
In fact that was the sole reason for me to move to the plain and simple
Apache FileUpload API.
-cheers,
Manish
Manish Pandit - 20 Sep 2006 21:24 GMT
Hi Dhanya,
This snippet might help with FileUpload:
1. Check if the request is multipart (which it has to be if you are
passing around files)
DiskFileItemFactory factory = new
org.apache.commons.fileupload.disk.DiskFileItemFactory();
factory.setRepository(new File(your_temp_folder));
ServletFileUpload upload = new ServletFileUpload(factory);
boolean isMultipart = upload.isMultipartContent(request);
2. Get the list of items
List<FileItem> items = upload.parseRequest(request);
3. Iterate through this list, and get the FileItems.
4. Check for the flag isFormField() on every FileItem you get - if
true, it is one of the form fields (text, etc) and if false, it is a
file. Put the stuff in your beans or DTOs accordingly. Check the
FormField API for more info on getting values/names etc.
Hope this helps!
-cheers,
Manish