java Spring mvc:HTTP 状态 400 - 所需的 MultipartFile 参数“文件”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25830503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring mvc: HTTP Status 400 - Required MultipartFile parameter 'file' is not present
提问by Stepan Yakovenko
This is my controller:
这是我的控制器:
@RequestMapping(value = "/admin/users/photo", method = RequestMethod.POST)
public ModelAndView editUser(@RequestParam("file") MultipartFile file,
Principal principal) {
// code never gets here
}
my mvc-dispatcher-servlet.xml
我的 mvc-dispatcher-servlet.xml
<bean id="multipartResolver"
class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</bean>
pom.xml:
pom.xml:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
form itself:
形式本身:
<form action="${pageContext.request.contextPath}"
method="POST"
enctype="multipart/form-data">
<input type="file"
name="file"
/>
<input type="submit" value="Добавить">
</form>
This is what browser says:
浏览器是这样说的:
How to fix that?
如何解决?
回答by stacky
You can try to use this
你可以尝试使用这个
<bean id="multipartResolver" class="**org.springframework.web.multipart.commons.CommonsMultipartResolver**" />
instead of
代替
<bean id="multipartResolver"
class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
回答by Honeymon
Servlet 3.0 specification.
Servlet 3.0 规范。
StandardServletMultipartResolver is Standard implementation of the {@link MultipartResolver} interface
StandardServletMultipartResolver 是 {@link MultipartResolver} 接口的标准实现