File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts2 multiple files upload with a twist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 multiple files upload with a twist" Watch "Struts2 multiple files upload with a twist" New topic
Author

Struts2 multiple files upload with a twist

Krishnaraj Jayachandran
Greenhorn

Joined: Nov 08, 2009
Posts: 2
Hello everyone!

Lets say I have the following model classes



My action is as follows


DAO


add_product.jsp



The images uploaded by the user has to go to their respective directories in the server (eg. file in 'small' has to go to 'images/small', 'large' to 'images/large'.. ). Now the problem is how can I associate the imageTypeId with each file ? I was able to solve this with some javascript trickery and hidden elements but is there any proper way to let struts2 handle this ?
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
You could try to use a HashMap<String, File> instead of list and name the inputs imageFiles.small, imageFiles.big, etc. Not sure this is going to work, but you can give it a try!

Or you could create a bean with big/small/etc. members and use this instead of List<File> and name the inputs as explained above, or give each input a different name and have a separate member in the class for each if the list of image types is not dynamic...


OCJP 6 (93%)
Krishnaraj Jayachandran
Greenhorn

Joined: Nov 08, 2009
Posts: 2
The reason for using a list was to let struts2 auto magically populate the imageFilesFileName .. not sure how to get this to work with a HashMap .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 multiple files upload with a twist
 
Similar Threads
need to transfer productID from url to action class in struts 2
How to retain automatically generated fields on pageload in struts2
Struts2 nested iterators with listboxes
Struts2: Problem with form validation using validation xml
Dynamic drop down in struts