aspose file tools*
The moose likes Struts and the fly likes How can I upload multiple files using html:file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can I upload multiple files using html:file" Watch "How can I upload multiple files using html:file" New topic
Author

How can I upload multiple files using html:file

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Hi guys,

I'm trying to upload multiple files using struts html:file tag. However, they all share one property name ("sourceFile"). So, I cannot read more than one file is my action class.

HERE's my code:

<bean efine id="count" name="imageCount" />

<%
int counter = new Integer(count);

for(int i=0; i < counter; i++)
{
%>

<tr>
<td>
<html:file property="sourceFile" accept="image/jpeg" />
</td>
</tr>


<%
}
%>

PLS...HeLP!!!
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
If you are using struts 2. Download struts. Check the struts2-showcase-2.0.6.war. It has an Action that handle multiple file uploads


SCJP1.4
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Yes...but the problem I'm having is there is one property name for all the files. So, if there are 20 different html:file displayed on a page, all 20 of them will have the same name.

For example:

<html:file property="sourceFile" accept="image/jpeg" />
<html:file property="sourceFile" accept="image/jpeg" />
<html:file property="sourceFile" accept="image/jpeg" />
<html:file property="sourceFile" accept="image/jpeg" />
<html:file property="sourceFile" accept="image/jpeg" />
...
...
<html:file property="sourceFile" accept="image/jpeg" />

This is being printed for a jsp for-loop not strut's iterate where I could use the indexed=true property.
Ajit Kanada
Ranch Hand

Joined: Jan 23, 2001
Posts: 95
Hi Nina,

Why dont you use the counter in your code to
create disctinct property values like

property="sourceFile1"
property="sourceFile2"
property="sourceFile3"
property="sourceFile4"

etc...

Cheers
Ajit


Thankx
Ajit
Abhilash George
Greenhorn

Joined: Apr 28, 2006
Posts: 13
hi
just make sure that each time a file is selected you make a call to you action class and put this selected file into a hashmap of Formfiles. Anytime you want to check the attached files just iterate through this hashmap. I have implemented such a scenario let me know if you need more details


george
 
 
subject: How can I upload multiple files using html:file