ApplicationHttpRequest cannot be cast to MultipartHttpServletRequest springMVC 文件上传转换出错解决

508 次查看

1、确认<form name=”contractForm” id=”contractForm” action=”” method=”post” enctype =”multipart/form-data”>;

2、确认commons-fileupload.jar 和 org.springframework.web.jar 存在环境

3、MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;

这一句会报错:ApplicationHttpRequest cannot be cast to MultipartHttpServletRequest

那就通过这种方式:

MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext());

MultipartHttpServletRequest multipartRequest = resolver.resolveMultipart(request);

赞赏


微信赞赏

支付宝赞赏

java架构师历程,欢迎扫描关注