download.jsp
来源:互联网 发布:linux宿主目录 编辑:程序博客网 时间:2024/06/07 22:18
以后拿来用。
<%@ page import="java.util.*"%><%@ page import="java.io.*"%><%@ page import="com.wondertek.meeting.model.*"%><%@ page import="com.wondertek.meeting.util.ValidateUtil"%><%//防止IE缓存 response.setHeader("pragma", "no-cache");response.setHeader("cache-control", "no-cache");response.setDateHeader("Expires", 0);//设置编码 request.setCharacterEncoding("UTF-8");MeetingFiles meetingFiles = (MeetingFiles) request.getAttribute("meetingFiles");System.out.println("downloading.....");System.out.println("meetingFiles.getFileSaveName():"+ meetingFiles.getFileSaveName());System.out.println("meetingFiles.getFileName():"+ meetingFiles.getFileName());System.out.println(config.getServletContext().getRealPath(meetingFiles.getFilePath() + File.separator+ meetingFiles.getFileSaveName()));java.io.BufferedInputStream bis = null;java.io.BufferedOutputStream bos = null;try {String fileSaveName = meetingFiles.getFileSaveName();//response.setContentType("application/octet-stream");response.setContentType("application/octet-stream;charset=UTF-8");//如果为WAP下载时String fileDownloadName = "";if ("WAP".equals(String.valueOf(request.getAttribute("from")))) {fileDownloadName = meetingFiles.getFileSaveName();} else {fileDownloadName = meetingFiles.getFileName();}System.out.println("是否属于IE:"+ValidateUtil.isIE());//IE下下载if(ValidateUtil.isIE()){response.setHeader("Content-disposition","attachment; filename="+ java.net.URLEncoder.encode(fileDownloadName,"utf-8"));}else{response.setHeader("Content-disposition","attachment; filename="+ new String(fileDownloadName.getBytes("UTF-8"), "ISO8859-1"));}String documentRoot = String.valueOf(request.getAttribute("documentRoot"));bis = new java.io.BufferedInputStream(new FileInputStream(documentRoot+meetingFiles.getFilePath()+ File.separator+ java.net.URLEncoder.encode(fileSaveName,"UTF-8")));bos = new java.io.BufferedOutputStream(response.getOutputStream());byte[] buff = new byte[2048];int bytesRead;while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {bos.write(buff, 0, bytesRead);}bos.flush();out.clear();//清空缓存的内容。out = pageContext.pushBody();//:参考API} catch (Exception e) {e.printStackTrace();} finally {if (bis != null)bis.close();if (bos != null)bos.close();}%>
判断是否为IE
* 判断是否为IE * @return */public static boolean isIE() {return ServletActionContext.getRequest().getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 ? true : false;}
- download.jsp
- JSP 页面 download txt 文件
- 用jsp实现文件的下载(download.jsp)
- download
- download
- download
- download
- Download
- download
- download
- download
- download
- download
- download
- downLoad
- download
- downLoad
- download
- 网络层次协议和结构体系之间的关系
- 我们的客户很豪爽
- Android 开发从入门
- 将程序移植到64位Windows
- 在windows 2003 server 上安装bugzilla
- download.jsp
- js中实现双击进行编辑的方法
- Spring中ClassPathXmlApplicationContext类的简单使用
- ABAP BAPI常用表
- QML Designer
- 写在2012
- android下xstream转换对象和xml
- 利用DataOutputStream写私密日记 无人能破解 暨 学习DataOutputStream和DataInputStream类
- Sencha Touch 2.0官方指南:如何使用数据视图