本文介绍了Spring mvc:HTTP状态400 - 所需的MultipartFile参数“文件”不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器:

pre $ @ $ c $ @RequestMapping(value =/ admin / users / photo,method = RequestMethod。 POST)
public ModelAndView editUser(@RequestParam(file)MultipartFile文件,
Principal主体){
//代码永远不会到达
}

我的mvc-dispatcher-servlet.xml

 < bean id =multipartResolver
class =org.springframework.web.multipart.support.StandardServletMultipartResolver>
< / bean>

pom.xml:

 <依赖项> 
< groupId> commons-fileupload< / groupId>
< artifactId> commons-fileupload< / artifactId>
< version> 1.3.1< / version>
< /依赖>

表格本身:

 < form action =$ {pageContext.request.contextPath}
method =POST
enctype =multipart / form-data>
< input type =file
name =file
/>
< input type =submitvalue =添加>
< / form>

这就是浏览器所说的:



如何解决这个问题?

解决方案

您可以尝试使用这个

 < bean id =multipartResolverclass =** org.springframework.web.multipart.commons.CommonsMultipartResolver **/> 

而不是

 < bean id =multipartResolver
class =org.springframework.web.multipart.support.StandardServletMultipartResolver>


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

<bean id="multipartResolver"
      class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</bean>

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?

解决方案

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">

这篇关于Spring mvc:HTTP状态400 - 所需的MultipartFile参数“文件”不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:01