2010-02-19 126 views
0

我有以下的ActionForm一个Struts 1应用程序:FormFile投掷ConversionException

import org.apache.struts.upload.FormFile; 

public class uploadedFileForm { 

public FormFile theFile; 

    public FormFile getTheFile() { 
     return theFile; 
    } 

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

我的JSP页面有以下形式:

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

当我提交表单,以我的Struts动作,我立即收到以下错误信息:

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

我试图添加一些调试语句到第我的行动的开始,但没有打印出来。这似乎表明Struts在达到我的操作之前抛出了这个错误。

有没有人有什么建议可能会导致此错误消息?

回答

2

问题与html:form标签有关。

我需要在html:form标签上同时使用method =“post”和enctype =“multipart/form-data”属性。

我的实际表单比较复杂,没有enctype =“multipart/form-data”属性。当我添加它时,一切正常。