HttpServletRequest转换成MultipartHttpServletRequest异常,求解
本人用的是springMVC和tomcat进行文件上传,xml中配置了<bean id="multipartResolver" name="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>
</bean>
代码中使用的是
public ModelAndView uploadFile(HttpServletRequest request,HttpServletResponse response) throws CswWebException{
UserInfoDto user= getUserInfomation(request);
MultipartHttpServletRequest multipartRequest=(MultipartHttpServletRequest)request;
MultipartFile multipartFile=multipartRequest.getFile("fileName");
但是还是报错:
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
虽然报错,但文件依然可以正常上传!求解! --------------------编程问答-------------------- 页面怎么提交的?直接访问这个方法?这个MultipartHttpServletRequest,要经过form表单才行的。而且还依赖commons-fileupload.jar commons-io.jar这俩包。 --------------------编程问答-------------------- ~这个,我是这样写的
public ModelAndView test(@RequestParam MultipartFile[] myfiles,HttpServletRequest request, HttpServletResponse response)
其中@RequestParam MultipartFile[] myfiles这个就是我上传的文件list
myfiles[下标].getInputStream()就可以去到文件的流!
然后就可以进行文件写入操作了! --------------------编程问答--------------------
我是用表单提交, --------------------编程问答-------------------- 就是表单提交的啊~~~表单里面有多少个input type=file的,那个数组里面就有多少个文件啊!
补充:Java , Java EE