<%@ page contentType="text/html;charset=gb2312" import="java.io.*"%><%
try{
String str=request.getParameter("name1");//获得响应客户的输出流
str=new String(str.getBytes("iso8859-1"),"gb2312");
File fileLoad=new File("f:\\tools\\xiazai",str);//下载文件
response.reset();
OutputStream o=response.getOutputStream(); BufferedOutputStream bos=new BufferedOutputStream(o);
byte b[]=new byte[500];//输出文件用的字节数组,每次发送500个字节到输出流
response.setHeader("Content-disposition","attachment;filename="+new String(str.getBytes("gb2312"),"iso8859-1")); response.setContentType("application/x-tar");//通知客户文件的mime类型
long fileLength=fileLoad.length();//通知客户文件的长度
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);
FileInputStream in=new FileInputStream(fileLoad);//读取文件并发送给客户下载
int n=0;
while((n=in.read(b))!=-1)
{
bos.write(b,0,n);
}
bos.close();
}
catch(Exception e){
out.println("发生了异常"+e);
}
response.reset();
%>
希望大家注释详细点,特别那个”response.reset()与response.setHeader()方法,按照书上说的我理解的不透希望大家帮我讲一下。这句也是第一次见,也不懂:""Content-disposition","attachment;filename"
再次谢谢大家了
try{
String str=request.getParameter("name1");//获得响应客户的输出流
str=new String(str.getBytes("iso8859-1"),"gb2312");
File fileLoad=new File("f:\\tools\\xiazai",str);//下载文件
response.reset();
OutputStream o=response.getOutputStream(); BufferedOutputStream bos=new BufferedOutputStream(o);
byte b[]=new byte[500];//输出文件用的字节数组,每次发送500个字节到输出流
response.setHeader("Content-disposition","attachment;filename="+new String(str.getBytes("gb2312"),"iso8859-1")); response.setContentType("application/x-tar");//通知客户文件的mime类型
long fileLength=fileLoad.length();//通知客户文件的长度
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);
FileInputStream in=new FileInputStream(fileLoad);//读取文件并发送给客户下载
int n=0;
while((n=in.read(b))!=-1)
{
bos.write(b,0,n);
}
bos.close();
}
catch(Exception e){
out.println("发生了异常"+e);
}
response.reset();
%>
希望大家注释详细点,特别那个”response.reset()与response.setHeader()方法,按照书上说的我理解的不透希望大家帮我讲一下。这句也是第一次见,也不懂:""Content-disposition","attachment;filename"
再次谢谢大家了
解决方案 »
- jfreechart 曲线不显示的问题
- 我还在吐血-第3问
- nullpointerexception问题的解决
- java执行cmd命令的基础问题
- applet如何读取jar文件中的文本文件?
- 如何在主程序中得到主程序生成的JFrame中函数的返回值?
- bluesmile979(笑着)等大侠请帮忙,关于上次的提问:如何在java里面调windows的ping。
- 问几个基础性的问题
- 我想做个类似资源管理器的东西,左边用jtree,右边用什么好呢?大侠请进,给个提示
- 请问大侠们 eclipse中Ctrl + 2 + L 这个快捷键怎么使用?
- 不能登进 oracle数据库, 报这个错?
- 定义xml问题!
建议自己debug跟一下,有个感性认识。