Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<html:file> upload file error , -argument type mismatch-

In my jsp i have a html:file like this, and in the form i have the getter and setter. but when running i got

Caused by: java.lang.IllegalArgumentException: Cannot invoke com.app.app.struts.forms.MyForm.setDocfile on bean class 'class com.app.app.struts.forms.MyForm'
    - argument type mismatch - had objects of type "java.lang.String" but expected signature "org.apache.struts.upload.FormFile"

jsp:

<html:file property="docfile" styleId="docfile" size="45" ></html:file>

getting the error only when submitting the page and i'm not uploading anything. (the upload field is not a required filed .)

like image 780
Elye M. Avatar asked Jan 10 '13 15:01

Elye M.


1 Answers

It seems to be problem with the encoding, the struts form doesn't recognize the submit as a type of file, make sure to set the form's enctype attribute to multipart/form-data and method as post.

So you should have:

<html:form action="/somePath" enctype="multipart/form-data" method="post"></html:form>

Be aware that this could mess up things with your validation. See this thread for more.

like image 90
meilechh Avatar answered Sep 23 '22 15:09

meilechh