1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
@RequestMapping(value = "/download", method = RequestMethod.GET) public void download(@RequestParam(value = "filename") String filename, HttpServletRequest request, HttpServletResponse response) throws IOException { String path =EXCEL_URL + "/" + filename; InputStream bis = new BufferedInputStream(new FileInputStream(new File(path))); filename = URLEncoder.encode(filename, "UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=" + filename); response.setContentType("multipart/form-data"); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); int len = 0; while ((len = bis.read()) != -1) { out.write(len); out.flush(); } out.close(); System.out.println(ExcelController.getIpAddr(request)+"下载完成"); }
|