Created
October 1, 2019 22:12
Revisions
-
yhzion revised this gist
Mar 8, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,5 +35,5 @@ } } } out.flush(); -
yhzion created this gist
Mar 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ File file = (File) model.get("downloadFile"); String fileName = (String) model.get("fileName"); String header = request.getHeader("User-Agent"); if (header.contains("MSIE") || header.contains("Trident")) { fileName = URLEncoder.encode(fileName,"UTF-8").replaceAll("\\+", "%20"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ";"); } else { fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1"); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); } response.setContentType(getContentType()); response.setContentLength((int) file.length()); response.setHeader("Content-Type", "application/octet-stream"); response.setContentLength((int)file.length()); response.setHeader("Content-Transfer-Encoding", "binary;"); response.setHeader("Pragma", "no-cache;"); response.setHeader("Expires", "-1;"); OutputStream out = response.getOutputStream(); FileInputStream fis = null; try { fis = new FileInputStream(file); FileCopyUtils.copy(fis, out); } catch (Exception e) { logger.error(e.getMessage()); } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { logger.error(e.getMessage()); } } } 38 39 out.flush();