|

楼主 |
发表于 2017-8-10 14:34:45
|
显示全部楼层
InputStream bis = null;
BufferedOutputStream bos = null;
String zipPath =request.getParameter("filepath");
System.out.println("---------"+zipPath);
//执行下载
response.setContentType("application/zip");
response.setCharacterEncoding("UTF-8");
//获取文件名
String tempFileNameSplit = zipPath.substring(zipPath.lastIndexOf("\\")+1, zipPath.length());
System.out.println(tempFileNameSplit);
//System.out.println(extend);
//将文件放在输入流中
bis = new BufferedInputStream(new FileInputStream(zipPath));
response.setHeader("Content-Disposition", "attachment; filename="+tempFileNameSplit);
response.setHeader("Content-Length", String.valueOf(bis.available()));
//创建输出流
bos = new BufferedOutputStream(response.getOutputStream());
//创建缓冲区
byte[] buff = new byte[2048];
int bytesRead;
//循环读取输入流中的内容到缓冲区
while ((bytesRead= bis.read(buff))>0) {
//输出流输出到浏览器,实现下载
bos.write(buff, 0, bytesRead);
}
bos.flush();
bos.close();
bis.close();
try {
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.close();
}
} catch (IOException e) {
e.printStackTrace();
//message+="下载压缩包时关闭输入输出流发生异常\r\n";
}
}
//.w文件的代码
var callback = function(xhr, ts){
if(justep.Request.isSuccess(xhr))
{
console.info(xhr);
}
else {alert('error');};
};
debugger;
justep.Request.sendHttpRequest(
justep.Request.setBizParams(justep.Request.convertURL('/UI/LandRenovation/ProjectList/process/projet/dsrc/download.j?filepath='+zippath)),
null,
"multipart/form-data",//"application/x-www-form-urlencode",
null,
null,
null,
null,
true,
callback);//访问servlet
}
}//if(data.state)
}
});//sendBizRequest2
}catch (e){
// TODO: handle exception
}
|
|