FormFile 抛出 ConversionException
我有一个带有以下 ActionForm 的 Struts 1 应用程序:
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
我尝试在 Action 的开头添加一些调试语句,但没有一个打印出来。这似乎表明 Struts 在执行我的操作之前抛出了此错误。
有人对可能导致此错误消息的原因有任何建议吗?
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() {
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题与
标记有关。标签上需要
method="post"
和enctype="multipart/form-data"
属性。我的实际表单更复杂,并且没有
enctype="multipart/form-data"
属性。当我添加它时,一切正常。The problem was related to the
<html:form>
tag.Both
method="post"
andenctype="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.