以后拿来用。
<%@ 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;
}
分享到:
相关推荐
1648381480463975_download.jsp
1617446759213071_download.jsp
1649047181229394_download.jsp
1730166058849171_download.jsp
1729073169402273_download.jsp
1728441905282536_download.jsp
1728152824180533_download.jsp
1728111538625210_download.jsp
1727400030441519_download.jsp
1727065032370053_download.jsp
1726322432766218_download.jsp
1725047453242909_download.jsp
1724982351832026_download.jsp
1713885093074609_download.jsp
1722435585540093_download.jsp
1719856762160904_download.jsp