我遇到了使用spring webflow 1.0和struts 1.3上傳文件的問題。Struts - 上傳文件
的JSP是這樣的:
<html:form action="/flowAction" method="post" enctype="multipart/form-data">
<!-- snip -->
<html:file property="file" name="attachDocumentsForm" size="50"/>
<!-- snip -->
</html:form>
的形式是這樣的:
public class AttachDocumentsForm extends SpringBindingActionForm {
// note, SpringBindingActionForm extends struts' ActionForm
private FormFile file;
//snip
}
現在,我的問題是,當我提交表單,該file
場總是null
。表單上的其他字段被正確填寫,如果我深入瞭解RequestContext
,我可以發現文件被深埋在那裏的一些數據結構中。
這裏是可怕醜陋的方式,我可以在附件獲得:
// 'context' is the RequestContext
ServletExternalContext servletExternalContext = (ServletExternalContext) context.getExternalContext();
ActionForm form = (ActionForm) servletExternalContext.getRequest().getAttribute("actionForm");
FormFile file = (FormFile) form.getMultipartRequestHandler().getFileElements().get("file");
我已經注意到,我的窗體上的MultipartRequestHandler
是null
,我懷疑這可能是部分問題,但我已經嘗試用CommonsMultipartRequestHandler
實例填充它無濟於事。
我需要做些什麼才能讓file
字段正確填充?
你不應該能夠得到從ActionForm中訪問該文件,使用(FormFile)form.getFile()? – 2009-10-01 02:37:42