根据文件路径,通过JSP将文件下载到本地
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%@ page import="java.util.*"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.OutputStream"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.util.zip.ZipOutputStream"%>
<%@ page import="java.io.BufferedInputStream"%>
<%
//下载文件的绝对路径(存放的服务器的地址)
String expFile = "E:/com/software/Adobe.exe";
//文件名
String fileName = "Adobe.exe";
String agent = request.getHeader("USER-AGENT");
response.reset();
response.setContentType("application/x-download");
if (agent != null && agent.toLowerCase().indexOf("firefox") > -1) {
response.addHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + fileName);
} else {
response.addHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
}
OutputStream outp = null;
FileInputStream in = null;
try {
outp = response.getOutputStream();
in = new FileInputStream(expFile);
byte[] b = new byte[1024];
int i = 0;
while ((i = in.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
in = null;
}
if (outp != null) {
outp.close();
outp = null;
out.clear();
out = pageContext.pushBody();
}
}
%>
<script type="text/javascript">
window.close();
</script>