报错场景:
使用SSM框架实现文件上传时报“Failed to instantiate [org.springframework.web.multipart.MultipartFile]”错,控制器源代码:
@Controller @RequestMapping("/file") public class FileUDController { @RequestMapping(value="/fileUpload",method=RequestMethod.POST) public ModelAndView fileUpload(MultipartFile file,HttpServletRequest req) { String path = req.getSession().getServletContext().getRealPath("upload"); String fileName = file.getOriginalFilename(); File dir = new File(path,fileName); if(!dir.exists()) { dir.mkdirs(); } try { file.transferTo(dir); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ModelAndView mv = new ModelAndView("success"