Multiple File upload - how to write the form bean

D

Dhanya

Hai ,
Can anybody help me in writing the form bean for multiple file upload
by giving a sample code?
Thanks in advance,
Dhanya
 
M

Manish Pandit

Do you absolutely have to use a form bean?

I guess that'd work too, but I have done it without a form bean, and
parsed the request at the server using DiskFileUpload (part of apache
file upload API).

-cheers,
Manish
 
D

Dhanya

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
 
M

Matt Humphrey

Dhanya said:
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.

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 (e-mail address removed) http://www.iviz.com/
 
M

Manish Pandit

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
Matt Humphrey wrote:
 
M

Manish Pandit

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top