<form action="user/excelImport.do" method="post" enctype="multipart/form-data"> 提交文件:<input type="file" name="file"><br><br> <input type="button" value="获取模板" οnclick="excel();"/><br><br> <input type="submit" value="确认" οnclick="refresh();"/> </form> @RequestMapping("/excelImport.do") @ResponseBody //MultipartFile file 文件过大需要导入commons-fileupload-1.3.jar //然后配置bean public void excelImport( @RequestParam("file") MultipartFile file, HttpServletRequest req,HttpServletResponse rep) throws IOException { @SuppressWarnings("deprecation") String Time =System.currentTimeMillis()+""; // 这里的路径是我项目中的文件夹的名称 String filePath = req.getRealPath("wdxsl")+"\\"+Time; File importExcel = new File(filePath); InputStream is = file.getInputStream(); FileOutputStream os = new FileOutputStream(importExcel); byte[] by = new byte[1024*10]; while(is.read(by)!=-1){ os.write(by); } is.close(); os.close(); }