开发者

FormFile Throwing ConversionException

开发者 https://www.devze.com 2022-12-21 04:00 出处:网络
I have a Struts 1 application with the following ActionForm: import org.apache.struts.upload.FormFile;

I have a Struts 1 application with the following ActionForm:

import org.apache.struts.upload.FormFile;

public class uploadedFileForm {

public FormFile theFile;

    public FormFile getTheFile() {
  开发者_如何学JAVA      return theFile;
    }

    public void setTheFile(FormFile theFile) {
        this.theFile = theFile;
    }
}

My JSP page has the following form:

<html:form action="/myAction" enctype="multipart/form-data">
<html:file property="theFile" onkeypress="return false;" />
</html:form>

When I submit the form to my Struts action, I immediately receive the following error message:

org.apache.commons.beanutils.ConversionException: Could not convert java.lang.String to org.apache.struts.upload.FormFile 

I tried adding some debug statements to the beginning of my Action, but none of them printed out. This seems to indicate that Struts is throwing this error before reaching my action.

Does anyone have any suggestion about what might be causing this error message?


The problem was related to the <html:form> tag.

Both method="post" and enctype="multipart/form-data" attributes are needed on the tag.

My actual form was more complex and didn't have the enctype="multipart/form-data" property. When I added it, everything worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消