日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

模板下载

發布時間:2025/3/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 模板下载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
function downloadExcelTemplate_Click(){var url = "downloadExcelTemplate.do?isdebug=true";location.href = url; }

  

/*** 下載導入模板** @param request* @param response* @return*/@RequestMapping(value = "/downloadExcelTemplate.do", method = RequestMethod.GET, produces = "application/json; charset=utf-8")@ResponseBodypublic ResponseModel downloadExcelTemplate(HttpServletRequest request, HttpServletResponse response) {ResponseModel responseModel = new ResponseModel();responseModel.setStatusCode("fail");String header = request.getHeader("User-Agent").toUpperCase();String fileName = "z中文";try {if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {fileName = URLEncoder.encode(fileName, "utf-8");fileName = fileName.replace("+", "%20"); //IE下載文件名空格變+號問題 }String filepath = request.getSession().getServletContext().getRealPath("/") +"excel/excel_route.xlsx";InputStream is = new FileInputStream(filepath);OutputStream os = setRespone(fileName, response);int length = 1024;int readLength = 0;byte buf[] = new byte[1024];readLength = is.read(buf, 0, length);while (readLength != -1) {os.write(buf, 0, readLength);readLength = is.read(buf, 0, length);}os.flush();os.close();responseModel.setStatusCode("success");} catch (UnsupportedEncodingException e) {getLogger().error("AccountInputController.downloadExcelTemplate method UnsupportedEncodingException :" + e.getMessage(), e);} catch (FileNotFoundException e) {getLogger().error("AccountInputController.downloadExcelTemplate method FileNotFoundException :" + e.getMessage(), e);} catch (Exception e) {getLogger().error("AccountInputController.downloadExcelTemplate method Exception :" + e.getMessage(), e);}return responseModel;} /*** 設置輸出響應下載流** @param fileName* @param response* @return* @throws IOException*/private OutputStream setRespone(String fileName, HttpServletResponse response) throws IOException {//輸出流OutputStream os = response.getOutputStream();//重置輸出流 response.reset();response.setContentType("application/vnd.ms-excel");//設置響應標題>這里瀏覽器會提示用戶選擇下載文件需要存放的路徑>//后續生成的文件在輸出流關閉后>action返回detailExcel進result指定響應內容為excel>自動寫入該excel到該用戶指定的路徑中response.setHeader("Content-disposition", "attachment; fileName=" + new String((fileName + ".xlsx").getBytes(), "iso8859-1"));//response.setHeader("Content-disposition", "attachment; fileName=" + URLEncoder.encode(brow,"utf-8")+".xls");(不可用)return os;}

?

轉載于:https://www.cnblogs.com/acme6/p/9237079.html

總結

以上是生活随笔為你收集整理的模板下载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。