• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I upload multiple files using html:file

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic