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

2

6

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

Silky answered 10/1, 2013 at 15:29 Comment(0)
R
11

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.

Rafter answered 11/1, 2013 at 14:16 Comment(2)
after a lil search i saw Use multipart/form-data whenever you have an <input type="file"> so i think its not only in struts,Silky
it should be <html:form enctype="multipart/form-data" ></html:form>. I'm sure it's a typo :)Rime
S
-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>
Sinew answered 6/1, 2018 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.