> Hi all,
> I need to use a FileUpload in a page and upload n
> files.
> What's the correct way to do this?Any examples?
>
> I've been thinking to store in a session parameter
> (File[ ])....
> It's a bad idea?
>
> thank's in advance!
First of all, every fileUpload component is good for one file only. So, if you need to upload n files, you simply need n fileUpload components. That said, you may use any of the following approaches:
1) If n is known beforehand, stack n fileUpload components and upload them one after the other. You need to be careful since if one of the files doesn't upload gracefully, you don't want to keep uploading files that have been uploaded correctly (a fileUpload component loses its input after an unsuccessful submit). You may need to make good use of virtual forms here.
2) If n is not known beforehand, easy. Once known, generate n fileUpload objects on the form programmatically.
3) If you still insist on wanting to upload the n files in one go, then may be you want to consider zipping them all first, upload the zipped file, and upzip it upon a successful upload. Java SE comes equipped with an API to help you zip and unzip a group of files from within your application. I could help you with the code if you need.
4) I don't have a 4 :-). If you get that (File[ ]) working, let us know please.