文件下载的其中之一种
来源:百度文库 编辑:神马文学网 时间:2024/04/27 18:21:45
<%
try
{
String path = request.getRealPath("/"); //取ROOT的当前目录
String filename=request.getParameter("filename");//取上一个页面传过来的文件名称
String str=CONV.toStr(request.getParameter("filePath"),"");//取上一个页面传过来的路径
str="F:/WEBROOT/EMS/"+str.substring(6);//组合出要下载文件的路径
String gMimetype = "";
Hashtable Ht = new Hashtable();
String name = "";
Ht.put(".doc", "application/msword");
Ht.put(".asf", "application/vnd.ms-asf");
Ht.put(".xls", "application/vnd.ms-excel");
Ht.put(".ppt", "application/vnd.ms-powerpoint");
Ht.put(".mmp", "application/vnd.ms-project");
Ht.put(".csv", "text/comma-separated-values");
Ht.put(".zip", "application/zip");
Ht.put(".rar", "application/rar");
String suffix = filename.substring(filename.lastIndexOf("."));
gMimetype = (String)Ht.get(suffix);
if(gMimetype == null || gMimetype.equals("") || gMimetype.equals("null"))
{
gMimetype = "application/octet-stream";
}
FileInputStream fileinputstream = new FileInputStream(str);//读取模块文件的内容
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
String templateContent = new String(bytes);
response.setContentType(gMimetype);
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(filename, "UTF-8"));
//注意, 上面的"java.net.URLEncoder.encode(filename, "UTF-8")"代码,能使中文名称的附件名不显示乱码!
out.write(templateContent);
out.flush();
out.close();
}
catch(Exception e)
{
out.print("异常");
out.print(e.toString());
}
%>
try
{
String path = request.getRealPath("/"); //取ROOT的当前目录
String filename=request.getParameter("filename");//取上一个页面传过来的文件名称
String str=CONV.toStr(request.getParameter("filePath"),"");//取上一个页面传过来的路径
str="F:/WEBROOT/EMS/"+str.substring(6);//组合出要下载文件的路径
String gMimetype = "";
Hashtable Ht = new Hashtable();
String name = "";
Ht.put(".doc", "application/msword");
Ht.put(".asf", "application/vnd.ms-asf");
Ht.put(".xls", "application/vnd.ms-excel");
Ht.put(".ppt", "application/vnd.ms-powerpoint");
Ht.put(".mmp", "application/vnd.ms-project");
Ht.put(".csv", "text/comma-separated-values");
Ht.put(".zip", "application/zip");
Ht.put(".rar", "application/rar");
String suffix = filename.substring(filename.lastIndexOf("."));
gMimetype = (String)Ht.get(suffix);
if(gMimetype == null || gMimetype.equals("") || gMimetype.equals("null"))
{
gMimetype = "application/octet-stream";
}
FileInputStream fileinputstream = new FileInputStream(str);//读取模块文件的内容
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
String templateContent = new String(bytes);
response.setContentType(gMimetype);
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(filename, "UTF-8"));
//注意, 上面的"java.net.URLEncoder.encode(filename, "UTF-8")"代码,能使中文名称的附件名不显示乱码!
out.write(templateContent);
out.flush();
out.close();
}
catch(Exception e)
{
out.print("异常");
out.print(e.toString());
}
%>
文件下载的其中之一种
文件的下载
下载视频的一种方法
下载视频的一种简
浏览器提示下载PHP文件的解决方法 -
如何恢复删除的文件(下载)
破解YYFC的歌曲文件下载
如何下载网上只能看不能下载的PPT文件?!
C# 文件操作(上传 下载 删除 文件列表...) - 《八零年代》.NET之家 - 博客...
[10-06-13] 时间转折点真的那么神秘? 介绍给你其中一种方法 - 股票投资 - 鼎...
下载FLV视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法0
00000000000000下载视频的一种简便方法
下载视频的一种简便方法goodone
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法
下载视频的一种简便方法