文件下载后页面如何自动关闭
页面代码
<%@ page language="java" contentType="text/html; charset=GB2312"
import="java.net.*,java.io.*"
%><%
response.setContentType("application/x-download");
String filename = request.getParameter("filename");
filename = new String(filename.getBytes("iso8859-1"),"gb2312");
String filenamedisplay = URLEncoder.encode(filename,"UTF-8");
String filenamedownload =this.getClass().getClassLoader().getResource("/").getPath()+"../../temp/"+filename;
System.out.print(filenamedownload);
response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try
{
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0)
{
output.write(b, 0, i);
}
output.flush();
}
catch(Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if(fis != null)
{
fis.close();
fis = null;
}
if(output != null)
{
output.close();
output = null;
}
}
%>