Java 所需的MultipartFile参数';文件';尝试上载文件时不存在错误
我不知道如何解决这个问题。在谷歌上搜索了几个小时却没有成功: 简单的例子: 我的jsp表单Java 所需的MultipartFile参数';文件';尝试上载文件时不存在错误,java,spring-mvc,file-upload,Java,Spring Mvc,File Upload,我不知道如何解决这个问题。在谷歌上搜索了几个小时却没有成功: 简单的例子: 我的jsp表单 <form method="post" action="/asd" enctype="multipart/form-data"> <input type="file" class="file" name="file"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.toke
<form method="post" action="/asd" enctype="multipart/form-data">
<input type="file" class="file" name="file"/>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="submit" value="Upload">
</form>
我的上下文xml文件
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- max upload size in bytes -->
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
<!-- max size of file in memory (in bytes) -->
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
</bean>
我的pom.xml中有
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version> <!-- makesure correct version here -->
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
文件上传
文件上传
1.3.1
公地io
公地io
2.4
我甚至在服务器的每个context.xml中添加了allowCasualMultipartParsing=“true”,如下所示:
<Context reloadable="true" allowCasualMultipartParsing="true">
但错误仍然存在,我不知道我做错了什么:
HTTP状态400–错误请求
类型状态报告
消息所需的多部分文件参数“file”不存在
说明由于以下原因,服务器无法或将不处理请求:
被认为是客户端错误的东西(例如,格式错误
请求语法、无效的请求消息帧或欺骗请求
路由)
ApacheTomcat/8.5.12
试试这个
在web.xml文件中添加以下筛选器
Web.xml
<!-- Support for File Upload And Download -->
<filter>
<display-name>springMultipartFilter</display-name>
<filter-name>springMultipartFilter</filter-name>
<filter- class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springMultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
springMultipartFilter
springMultipartFilter
org.springframework.web.multipart.support.MultipartFilter
springMultipartFilter
/*
并且在您的上下文文件中使用filterMultipartResolver而不是multipartResolver,因为Spring安全依赖性如下所示
<!-- Support For File Upload And Download -->
<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000000" />
</bean>
是的,干杯
<!-- Support For File Upload And Download -->
<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000000" />
</bean>