Ext 实现文件的下载简要步骤:
1)为某个控件编写事件响应代码
2) 编写后台的java代码
以上代码本人测试可以下载chm格式的文件。不错下载后会提示"未知发布者"导致文件打开后都是 ”已取消到该网页的导航“ 无法阅读。
把 ”打开此文件前总是询问“钩去掉就可以用了
1)为某个控件编写事件响应代码
handler:function()
{
// 可以使用下面两种方法中的一种来跳转到后台进行下载,也可以在后面传递参数
// document.location.href="chmDownload.do"
window.open("chmDownload.do");
}
2) 编写后台的java代码
// 设置相应的头部分
response.setContentType("application/x-download");
response.setHeader("Content-disposition", "attachment;filename="+filename);
// 通过流进行连接,提供下载 ,doc_downPath就是要下载文件的路劲
OutputStream outputStream = null;
FileInputStream fileInputStream = null;
outputStream = response.getOutputStream();
fileInputStream = new FileInputStream(doc_downPath);
byte[] b = new byte[1024];
int length = 0;
while((length = fileInputStream.read(b)) > 0) {
outputStream.write(b, 0, length);
}
outputStream.flush();
fileInputStream.close();
outputStream.close();
以上代码本人测试可以下载chm格式的文件。不错下载后会提示"未知发布者"导致文件打开后都是 ”已取消到该网页的导航“ 无法阅读。
把 ”打开此文件前总是询问“钩去掉就可以用了