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

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);

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论