//设置响应头
response.setContentType("application/force-download");
//给客户端传送文件名
String aa="湖南aa.zip";
aa=URLEncoder.encode(aa,"utf-8");
response.setHeader("Content-Disposition", "attachment;filename=\""+aa+"\"");//需要加这个attachment,不然成了浏览
String fileName=request.getParameter("fileName");
fileName=this.getServletContext().getRealPath(fileName);
InputStream in=new FileInputStream(fileName);
OutputStream out=response.getOutputStream();
byte b[]=new byte[1024];
int len=0;
while((len=in.read(b))!=-1){
out.write(b,0,len);
}
流的使用,输入输出流,中文要编码 aa=URLEncoder.encode(aa,"utf-8");要获取协议头