web.xml片段: <servlet> <servlet-name>springServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> servlet.xml片段: <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 设置上传文件的最大尺寸为10MB --> <property name="maxUploadSize"> <value>100010485761</value> </property> </bean> Controller: @RequestMapping(params = "method=upload") protected ModelAndView uploadFile(HttpServletRequest request) throws Exception { try{ //cast to multipart file so we can get additional information MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file"); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); byte[] bytes = file.getBytes(); String uploadDir = "c://uploadFile"; System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + uploadDir); File dirPath = new File(uploadDir); if (!dirPath.exists()) { dirPath.mkdirs(); } String sep = System.getProperty("file.separator"); if (log.isDebugEnabled()) { log.debug("uploading to: " + uploadDir + sep + file.getOriginalFilename()); } File uploadedFile = new File(uploadDir + sep + file.getOriginalFilename()); FileCopyUtils.copy(bytes, uploadedFile); System.out.println("********************************"); System.out.println(uploadedFile.getAbsolutePath()); System.out.println(bytes.length); System.out.println("********************************"); }catch(Exception e){ e.printStackTrace(); } return new ModelAndView(""); } 页面: <form method="post" action="collParam.do?method=upload" enctype="multipart/form-data"> <input type="file" name="file" id="file"/> <input type="submit" value="save"/> </form>