<%
// 得到文件名字和路径
String filen
ame = request.getParameter("filename");
String filepath = "c:\\";
// 设置响应头和下载保存的文件名
response.setContentTy
PE("APPLICATION/
octet-sTREAM";
response.setHeader("Content-Dispos
ITion","attachment; filename=\"" + filename + "\"";
// 打开指定文件的流信息
java.io.Fil
einputStream fileInputStream=new java.io.FileInputStream(filepath + filename);
// 写出流信息
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();
%>
<ht
ML>
<head>
<script language=javascript>
window.close()
</script>
</script>
</head>
<body>
</body>
</html>
et 设置为 _blank ,让它在新页面打开,这样页面不会跳转,close()函数才会执行.