流形式下载文件(结合POI生成excel使用)
2015-12-23 16:17
585 查看
<span style="font-size:18px;"> String downFileName; //配置本地生成路径 String savePath = "E:/"; if (exportType.equals("0")) { downFileName = I18NUtil.getMessage(request, "employee.iodata.exportreport") + ".xls"; downFileName = URLEncoder.encode(downFileName, "UTF-8"); savePath += downFileName; exportIOData(name, employeeId, serial, areaId, doorId, cardType, doorStatus, beginDate, endDate, savePath, request); } else if (exportType.equals("1")) { downFileName = I18NUtil.getMessage(request, "doorstatus.detail.report.note") + ".xls"; downFileName = URLEncoder.encode(downFileName, "UTF-8"); savePath += downFileName; exportDoorStatus(doorId, areaId, doorStatus, beginDate, endDate, savePath, request); } else { downFileName = I18NUtil.getMessage(request, "report.urgentenvnt.type.note") + ".xls"; downFileName = URLEncoder.encode(downFileName, "UTF-8"); savePath += downFileName; byte eventType = 2; exportUrgentEvent(eventType, urgentType, beginDate, endDate, savePath, request); } //File file = new File(savePath); // 设置response的Header /* response.addHeader("Content-Disposition", "attachment;filename=" + new String(downFileName.getBytes("utf-8"), "iso-8859-1")); //转码之后下载的文件不会出现中文乱码 response.addHeader("Content-Length", "" + file.length()); //需将后缀名一同转码,否则会造成下载无扩展名 response.reset();*/ // 清空response response.reset(); response.setContentType("application/msexcel");//设置生成的文件类型 response.setCharacterEncoding("UTF-8");//设置文件头编码方式和文件名 response.setHeader("Content-Disposition", "attachment; filename="+ new String(downFileName.getBytes("utf-8"), "ISO8859-1")); try { //以流的形式下载文件 //savePath = new String(savePath.toString().getBytes("utf-8")); // savePath = URLEncoder.encode(savePath, "UTF-8"); InputStream fis = new BufferedInputStream(new FileInputStream(savePath)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); toClient.write(buffer); toClient.flush(); toClient.close(); } catch (Exception e) { e.printStackTrace(); }</span>
相关文章推荐
- INSTALL_FAILED_UPDATE_INCOMPATIBLE
- C++学习笔记-关联容器
- Adb
- DUBBO配置规则详解
- unity, 动态创建节点时一定要先指定父节点再设置transform
- include layout scllorview 常用正则 base 64 网络请求框架
- 路哥教你搭建ssh框架
- C++ public,protected,private继承与访问限制
- iOS之通过PaintCode快速实现交互动画的最方便方法 未解问题
- SO_LINGER使用
- php获取服务器系统信息
- 初识Hadoop's Ecosystem
- AD账户UserAccountControl对应的值
- 不得不分享的JavaScript常用方法函数集(上)
- 过滤器
- Android Accessibility(辅助功能) --实现Android应用自动安装、卸载
- 实现DUBBO服务环境隔离
- IOS OC笔试题、swift、OC
- Mysql小知识
- asp.net mvc3.0安装失败之终极解决方案