org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.Mult
最新推荐文章于 2020-09-21 18:14:38 发布
qq_29750461
最新推荐文章于 2020-09-21 18:14:38 发布
阅读量1.1w
Java
.lang.ClassCastException: org.apache.catalina.connector.RequestFacade
cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
在用springMvc做上传文件的时候报这个错误,在网上查了一天,总结一下大致有几种情况:
1: jsp页面的表单没有设置 enctype="multipart/form-data"。
此处有个重点:一定要是method="post",如果没有定义请求方式,也一定会转化出错!!!
<form action="" method="post" enctype="multipart/form-data">
2:springMvc中没有配置文件上传:
-
<bean id="multipartResolver"
-
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
-
<!-- set the max upload size100MB -->
-
<property name="maxUploadSize">
-
<value>104857600</value>
-
</property>
-
<property name="maxInMemorySize">
-
<value>4096</value>
-
</property>
-
<property name="defaultEncoding">
-
<value>utf-8</value>
-
</property>
-
</bean>
3:必要的jar包没有导入。
4:如果你上边的都没有问题,那么就是你只用了一个浏览器在测试,要清除缓存!!对,没有错,缓存!!
spring
mvc 上传时
org
.
apache
.
cat
a
lin
a.
connector
.
Request
Facade
cannot be
cas
t to
org
.
springframework
.
web
.
multipart
.
Multipart
HttpServlet
Request
添加配置:
<bean id="
multipart
Resolver"...
java.lang.Class
Cas
tException:
org
.
apache
.
cat
a
lin
a.
connector
.
Request
Facade
cannot be
cas
t to
org
.
springframework
.
web
.
multipart
.
Multipart
HttpServlet
Request
>>>>>>>>>&g...
java.io.IOException: java.lang.Class
Cas
tException: Cannot
cas
t
org
.
springframework
.
web
.
Spring
Servlet
这个异常,一般是项目里引入了如下依赖:
<dependency>
<groupId>javax.servlet</groupId>
<ar...
java.lang.Class
Cas
tException:
org
.
apache
.
cat
a
lin
a.
connector
.
Request
Facade
cannot be
cas
t to
org
.
springframework
.
web
.
multipart
.
Multipart
Request
com.wa.editor.xheditor.controller.UploadController.uploa
import com.etc.service.UpLoadService;
import
org
.
apache
.commons.fileupload.servlet.ServletFileUpload;
import
org
.
springframework
.beans.factory.annotation.Autowired;
Spring
MVC文件上传报错:
java.lang.Class
Cas
tException:
org
.
apache
.
cat
a
lin
a.
connector
.
Request
Facade
cannot be
cas
t to
org
.
springframework
.
web
.
multipart
.
Multipart
HttpServlet
Request
.......
1.先看下页面的form表单中是否添加了: enctype =“
multipart
/form-data”
2.
spring
MVC appli
cat
io
四种思路java.lang.Class
Cas
tException:
org
.
apache
.
cat
a
lin
a.
connector
.
Request
Facade
cannot be
cas
t....
接思路一:直替换参数为需要的
request
,因为
public interface
Multipart
HttpServlet
Request
extends HttpServlet
Request
,
Multipart
Request
,
上一篇文章在开始,大家可能注意到和大多数博客