<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>104857600</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
<property name="defaultEncoding" value="GBK" />
</bean>
没啥问题。。
又检查了前端页面表单,也增加了属性enctype =“multipart/form-data”
<form id="formfile" method="post" action="uploadFile.do" enctype="multipart/form-data" >
依旧没有解决问题
而且出现了一个诡异的问题,当我用一下形式获取文件时,就不会报强制类型转换的错误
CommonsMultipartFile file = (CommonsMultipartFile) ((MultipartHttpServletRequest) request).getFile("fileuploadname");
最后偶然发现,当我给项目增加上
xmlbeans-2.6.0.jar
这个jar包后,问题解决了,原因嘛,没找到(囧)
SpringMVC文件上传报错:
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest.......
1.先看下页面的form表单中是否添加了: enctype =“multipart/form-data”
2.springMVC applicatio
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
写错成了:
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpS..
报错内容:
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
at com.hestia.mosa.inventory.contr...
org.apache.catalina.connector.RequestFacade cannot be cast to MultipartHttpServletRequest
网上搜索大多都是表单设置不严谨,或者配置文件不对,缺少Jar包之类。
我这测试原因也很简单,原本的表单中包含了文件数据,如果没有提交或者有人访问这个恶意请求不带文件,Spring就会抛出错误 。
MultipartHttpServletRequest multipartRequest= (MultipartHttpServletRequest)request;
转型报错cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
添加jar包commons-io.jar
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade
cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
实现springMvc文件上传报如上错误:
问题出现的原因
错误信息:
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
at sun.reflect.NativeMet...