网页下载模板前台后台
来源:互联网 发布:htc windows phone 编辑:程序博客网 时间:2024/04/30 16:59
前台
$(function(){ $("tbody").on("click",".dyzs",function(){ window.location.href=ctx+"/tzsb/DCDoc"; });});
当点击时跳转页面,不能用ajax,必须用action或链接。
action
@Action(value="DCDoc", results={@Result(type="json",params={"root","res"})}) public void DCDoc() throws Exception{ res=new ResultObject(); HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String path = "D:\\wzgzpt\\web\\template"; //String path2 = request.getSession().getServletContext().getRealPath( // "/resources"); //String path = ""; String fileName = "气瓶使用登记证.doc"; String filePath = path + "\\" + fileName; res.setMsg("ok"); publicFunc.downLoadFile(filePath, response, fileName, "doc"); }
downLoadFile方法
public static boolean downLoadFile(String filePath, HttpServletResponse response, String fileName, String fileType) throws Exception { File file = new File(filePath); //根据文件路径获得File文件 //设置文件类型(这样设置就不止是下Excel文件了,一举多得) if("pdf".equals(fileType)){ response.setContentType("application/pdf;charset=GBK"); }else if("xls".equals(fileType)){ response.setContentType("application/msexcel;charset=GBK"); }else if("doc".equals(fileType)){ response.setContentType("application/msword;charset=GBK"); } //文件名 response.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes(), "ISO8859-1") + "\""); response.setContentLength((int) file.length()); byte[] buffer = new byte[4096];// 缓冲区 BufferedOutputStream output = null; BufferedInputStream input = null; try { output = new BufferedOutputStream(response.getOutputStream()); input = new BufferedInputStream(new FileInputStream(file)); int n = -1; //遍历,开始下载 while ((n = input.read(buffer, 0, 4096)) > -1) { output.write(buffer, 0, n); } output.flush(); //不可少 response.flushBuffer();//不可少 } catch (Exception e) { //异常自己捕捉 } finally { //关闭流,不可少 if (input != null) input.close(); if (output != null) output.close(); } return false; }
0 0
- 网页下载模板前台后台
- java后台利用模板生成Word文档提供前台下载
- 14套网页后台html+css模板下载
- 后台模板下载
- thinkphp5 引入前台、后台模板方法
- web前台后台实现下载功能
- 前台ajax请求后台实现下载
- TemplateWorld-网页模板下载
- phpcms-前台模板调用和后台模板调用
- 整理的后台模板下载
- bootstrap后台adnub模板下载
- 后台处理前台模板例子(tmp文件)
- js-引擎模板前台后台(java)实战
- H5网站模板——前台和后台
- Android关于后台下载前台通知更新进度条的问题
- jquery开发网站后台模板源代码下载
- NSURLSession前台下载/后台下载/断点下载的代理执行路径(一)
- NSURLSession前台下载/后台下载/断点下载的代理执行路径(二)
- Node.js + Web Socket 打造即时聊天程序嗨聊
- iOS如何隐藏NavigationBar
- 聚类分析-实现亚洲足球聚类
- 提示Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Too
- 基于dubbo框架下的RPC通讯协议性能测试
- 网页下载模板前台后台
- norm--求矩阵和向量的范数
- 利用HTML和CSS实现常见的布局
- Unity3d使用PlayerPrefs类实现数据存档
- ROS进阶学习笔记(10)- 搭建自己的Turtlebot(5) - Interactive Makers
- 装系统--UEFI的电脑
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、划线等等)
- 使用putty ss
- OC_10_01 单例模式