62,614
社区成员
发帖
与我相关
我的任务
分享
<form name="frm" action="/platform/createxmlFile.do?actionType=downLoadFiles" method="post">
function downLoadFiles(){
var fxm = document.forms[0];
fxm.action = "/platform/createxmlFile.do?actionType=downLoadFiles&fileName=20140630_130000_ZMBX_0001_01.zip";
fxm.submit();
}
public void downLoadFiles(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String fileName = request.getParameter("fileName");
response.setContentType("application/OCTET-STREAM;charset=UTF-8");
String path = "E:\\file";
response.setHeader("Content-Dispositon", "attachment;filename="
+ URLEncoder.encode(fileName, "utf-8"));
File file = new File(path, fileName);
FileInputStream fis = null;
BufferedOutputStream bos = null;
try {
fis = new FileInputStream(file);
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[1024];
int len;
while ((len = fis.read(buffer)) != -1) {
bos.write(buffer, 0, len);
bos.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
fis.close();
bos.close();
}
}