项目比较老,框架不是很灵活,遇到上传文件的问题,实验了俩个小时终于搞定。
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);