Jeremiah Johnson wrote:
I would like to upload multiple files on a single web page by having
multiple <html:file> elements. The exact number of these are different
depending on the user who is using the application. So I want to store
this in an array (FormFile[]) in order to have N number of files
uploaded. When I try to use <html:file/> tags in an iterate loop (with
indexed="true") I get an error about requiring property attribute.
There's isn't a good way of doing that so I just rendered the the HTML
with scriplets. It looks something like:
<input type="file" name="workingfile"/>
<input type="file" name="notworkingfile[0]"/>
<input type="file" name="notworkingfile[1]"/>
<input type="file" name="notworkingfile[2]"/>
That should probably be name="notworkingfile(0)" -- i.e. parentheses
instead of brackets.
The form has getters and setters for workingfile (of type FormFile) and
notworkingfile ( of type FormFile[] that is 3 elements). workingfile is
assigned an instantied object however each element of notworkingfile[]
is null after submit.
I then attempted to use commons-fileupload-1.1.1 in a struts action
(struts 1.2.9) to read the uploaded data but it does not recognize that
any files are being uploaded (including workingfile). I tried this code:
List items = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
items results in an empty collection (but not null). I've read that you
can not use commons-fileupload in a struts action which may be why that
No, that won't work since by the time commons-fileupload parses the
request, it's already been read by Struts. As you've already discovered,
Struts is handling the uploaded files for you -- you just need to get
your form bean and property references straight so you can see them.
doesn't work. Anyone know how to have variable number of file upload
boxes? I know I could have properties for each file (file1,file2,file3
and so on) instead of array but I'd rather not implement it that way.
See the documentation on using indexed properties [1] for more details.
L.
[1] http://struts.apache.org/1.2.x/faqs/indexedprops.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]