Search code examples
javastruts

Upload multiple files in a JSP


How to upload multiple files in a JSP?

I have a list of eight Questions, I want attachments for each question, when I am submitting the form I am getting the following error. Please help me in solving this

"Caused by: java.lang.IllegalArgumentException: Cannot invoke 
  com.usrinfo.form.AssessmentForm.setAttatchment on bean class 
  'class com.usrinfo.form.AssessmentForm' - argument type mismatch - 
  had objects of type "java.util.ArrayList" but expected 
  signature "org.apace.struts.upload.FormFile"

this is my input type:

<input class="" type='file' style="display:none;" name="attachment" id="<%=q.getId()%>file"/>

This is my action

action="xxx.do"  method="post" enctype="multipart/form-data">

Solution

  • According to the message, Struts is trying to set a List<FormFile> on your AssessmentForm, but your AssessmentForm class only has setAttachment(FormFile). If you change it to List<FormFile>, Struts will be able to set the list of FormFiles and you can iterate over that to process them.