Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Multiple File upload - how to write the form bean

Thread view: 
Dhanya - 18 Sep 2006 11:37 GMT
Hai ,
Can anybody help me in writing the form bean for multiple file upload
by giving a sample code?
Thanks in advance,
Dhanya
Manish Pandit - 18 Sep 2006 20:09 GMT
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

> Hai ,
> Can anybody help me in writing the form bean for multiple file upload
> by giving a sample code?
> Thanks in advance,
> Dhanya
Dhanya - 20 Sep 2006 07:51 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.