gpt4 book ai didi

java - Spring MVC : HTTP Status 400 - Required MultipartFile parameter 'file' is not present

转载 作者:行者123 更新时间:2023-11-29 03:17:11 30 4
gpt4 key购买 nike

这是我的 Controller :

@RequestMapping(value = "/admin/users/photo", method = RequestMethod.POST)
public ModelAndView editUser(@RequestParam("file") MultipartFile file,
Principal principal) {
// code never gets here
}

我的 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 action="${pageContext.request.contextPath}"
method="POST"
enctype="multipart/form-data">
<input type="file"
name="file"
/>
<input type="submit" value="Добавить">
</form>

这是浏览器说的:

http 400

如何解决?

最佳答案

你可以试试这个

<bean id="multipartResolver" class="**org.springframework.web.multipart.commons.CommonsMultipartResolver**" />

代替

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

关于java - Spring MVC : HTTP Status 400 - Required MultipartFile parameter 'file' is not present,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830503/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com