我的 jspx 页面中有一个表单,如下所示:
<form class="form-horizontal no-margin uploadform" action="/webapp/post" method="POST" encoding="multipart/form-data" enctype="multipart/form-data">
<input type="text" name="nomfichact" id="nomfichact" />
<input id="content" name="content" type="file"
style="display: none;"
accept="image/x-png, image/gif, image/jpeg" />
<input readonly="readonly" class="input-large" type="text" />
<a onclick="$('input[id=content]').click();">Choose file</a>
</form>
至于服务器端,我使用 spring mvc 来捕获文件,如下所示:
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data", produces = "text/html")
public String create(@Valid UploadedFile mediaUpload, HttpSession session, BindingResult bindingResult, Model uiModel,
HttpServletRequest httpServletRequest){
CommonsMultipartFile content = mediaUpload.getContent();
this.save((FileInputStream)content.getInputStream());
}
这与 firefox 完美配合,但使用 ie8 或 ie9 这不起作用并返回 null。我已经阅读了关于编码的内容,我应该在表单上放置 enctype 和编码标签,但这并没有起到作用。提前致谢
uploadfile 类定义包含:
@Transient
private CommonsMultipartFile content;
public CommonsMultipartFile getContent() {
return content;
}
public void setContent(CommonsMultipartFile content) {
this.content = content;
}