Commit 49db559e58ca0ae15ca43bb865c165194e4c1fd7

Authored by yiming
1 parent 0a3ca977

模板下载 重置密码

src/main/java/com/bsth/controller/DownloadController.java
... ... @@ -144,4 +144,27 @@ public class DownloadController
144 144 //目录此时为空,可以删除
145 145 return files.delete();
146 146 }
  147 +
  148 + @RequestMapping("download3")
  149 + public void download3(HttpServletResponse response,String fileName)
  150 + throws IOException {
  151 +// String fileNames=URLDecoder.decode(fileName,"UTF-8");
  152 + if(!fileName.contains(".xls"))
  153 + fileName =fileName + ".xls";
  154 + String moudelPath = this.getClass().getResource("/").getPath()+ "static/pages/forms/export/"+fileName;
  155 + File file = new File(moudelPath);// path是根据日志路径和文件名拼接出来的
  156 +// String filename = file.getName();// 获取日志文件名称
  157 + InputStream fis = new BufferedInputStream(new FileInputStream(moudelPath));
  158 + byte[] buffer = new byte[fis.available()];
  159 + fis.read(buffer);
  160 + fis.close();
  161 + response.reset();
  162 + response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.replaceAll(" ", "").getBytes("utf-8"),"iso8859-1"));
  163 + response.addHeader("Content-Length", "" + file.length());
  164 + OutputStream os = new BufferedOutputStream(response.getOutputStream());
  165 + response.setContentType("application/octet-stream");
  166 + os.write(buffer);// 输出文件
  167 + os.flush();
  168 + os.close();
  169 + }
147 170 }
... ...
src/main/resources/static/pages/ddexam/index.html
... ... @@ -262,6 +262,6 @@
262 262 })
263 263 }
264 264 function download(){
265   - window.open("/downloadFile/download?fileName=import_student.xlsx");
  265 + window.open("/downloadFile/download3?fileName=import_student.xlsx");
266 266 }
267 267 </script>
268 268 \ No newline at end of file
... ...