- 前台代码
1 //模板下载 2 templatesDownload : function(){ 3 var form = $("<form>"); //定义一个form表单 4 form.attr(‘style‘, ‘display:none‘); //在form表单中添加查询参数 5 form.attr(‘target‘, ‘‘); 6 form.attr(‘method‘, ‘post‘); 7 form.attr(‘action‘, getPath() + ‘/ExpertLibController.json?getBatchImportTemplate=true‘); 8 $(‘body‘).append(form); //将表单放置在web中 9 form.submit().remove(); 10 },
- 后台处理
1 /** 2 * 模板下载 3 */ 4 @RequestMapping(params = "getBatchImportTemplate") 5 public void getBatchImportTemplate(HttpServletRequest request, HttpServletResponse response){ 6 response.setCharacterEncoding("UTF-8"); 7 response.setContentType("application/octet-stream"); 8 response.setHeader("Content-disposition","attachment;filename=batchExpertsTemplate.xls"); 9 try { 10 FileInputStream fis = new FileInputStream(request.getSession().getServletContext().getRealPath("/zjfxjk/expertsLib/templates/batchExpertsTemplate.xls")); 11 System.out.println("清单批量 rar 文件路径:"+request.getSession().getServletContext().getRealPath("/zjfxjk/expertsLib/templates/batchExpertsTemplate.xls")); 12 IOUtils.copy(fis,response.getOutputStream()); 13 fis.close(); 14 } catch (Exception e) { 15 e.printStackTrace(); 16 } 17 }
原文地址:https://www.cnblogs.com/zhangjieatbky/p/8176440.html
时间: 2024-11-05 19:38:13