• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 multiple files upload with a twist

 
Krishnaraj Jayachandran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Krishnaraj Jayachandran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic