Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I upload multiple files using html:file

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Abhilash George
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic