,想跟你请教个问题:使用springmvc做文件上传 :
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartRequest.getFile("filename");
String fileName = multipartFile.getOriginalFilename();
try {
binaryStream = multipartFile.getBytes();
} catch (IOException e) {
log.error("MessageUtil.getFileFromWeb.IOException.error:",e);
}
tomcat中能正常将request转为MultipartHttpServletRequest,但在resin中则包转换异常?如下:怎么搞搞
org.springframework.web.util.NestedServletException: Request processing
failed; nested exception is java.lang.ClassCastException: com.caucho.server.http.HttpServletRequestImpl
cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
在你的spring mvc的配置文件中加上
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="5120000" p:maxInMemorySize="512" />
还要保证有commons-fileupload.jar commons-io.jar这两个jar包
File file = new File(“目标文件夹”,"想要保存后的文件名");
multipartFile.transferTo(file);
这样就可以了····