5

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 .)

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Elye M.
  • 2,667
  • 4
  • 30
  • 43

2 Answers2

10

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.

Community
  • 1
  • 1
meilechh
  • 825
  • 2
  • 8
  • 17
-1

add this dependencies to your project:

    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
    </dependency>
Alireza
  • 1
  • 2