ENDRPrint_12CRelease/web/download.jsp
2024-08-14 10:58:03 +07:00

31 lines
959 B
Plaintext

<%@ page import="java.io.*" %>
<%@ page import="java.net.URLEncoder" %>
<%
String filename = request.getParameter("path");
response.reset();
response.setContentType("APPLICATION/OCTET-STREAM");
// response.setContentType("application/download");
// response.setHeader("Content-Disposition","attachment;filename=\"" + filename + "\"");
response.setHeader("Content-Disposition","attachment;filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
File fileToDownload = new File(filename);
InputStream in = null;
ServletOutputStream outs = response.getOutputStream();
try {
in = new BufferedInputStream(new FileInputStream(fileToDownload));
int ch;
while ((ch = in.read()) != -1) {
// outs.print((char) ch);
outs.write(ch);
}
}
finally {
if (in != null) in.close(); // very important
}
outs.flush();
outs.close();
in.close();
%>