<%@ page contentType="application/x-download" import="java.io.*" %>
<%
int status=0;
byte b[]=new byte[1024];
FileInputStream in=null;
ServletOutputStream out2=null;
try
{
status=in.read(b);
out2.write(b);
}
out2.flush();
}
catch(Exception e)
{
System.out.println(e);
response.sendRedirect("downError.jsp");
}
finally
{
if(in!=null)
in.close();
if(out2 !=null)
out2.close();
}
%>
<%
int status=0;
byte b[]=new byte[1024];
FileInputStream in=null;
ServletOutputStream out2=null;
try
{
response.setHeader("content-disposition","attachment; filename=d.zip");
//当Content-Type 的类型为要下载的类型时 , 这个信息头会告诉浏览器这个文件的名字和类型。
in=new FileInputStream("D:\\kk.html");
//将要下载的文件读入内存中
out2=response.getOutputStream();
/*
public abstract class ServletOutputStream extends OutputStream
这是一个由Servlet引擎使用的抽象类。Servlet通过使用ServletResponse接
口的使用获得了对一个这种类型的对象的说明。利用这个输出 流可以将数据返
回到客户
while(status != -1 )
{status=in.read(b);
out2.write(b);
}
out2.flush();
}
catch(Exception e)
{
System.out.println(e);
response.sendRedirect("downError.jsp");
}
finally
{
if(in!=null)
in.close();
if(out2 !=null)
out2.close();
}
%>