downlaod 文件的窗口

(1)  如果文件是可访问的web资源, <a href=""> 最简洁。

(2) 如果是动态生成的资源:

server端:

response.setContentType("application/octet-stream;"); //Mime类型,随文件而变

response.addHeader("Content-Disposition", "attachment;filename=\""

  + URLEncoder.encode(responseFileName, "UTF-8") + "\"");

ous = response.getOutputStream();

ous = new BufferedOutputStream(ous);

ins = new BufferedInputStream(new FileInputStream(exportFile));

org.apache.commons.io.IOUtils.copy(ins, ous);

js端:

var urlStr = "/xxx/xxx/xx.action;jsessionid="+ window.jsessionid+"?resId=" + resId;

//window.open(urlStr, "_blank");

window.open(urlStr, "downframe");//参数target使用“downframe”会打开浏览器的download窗口

以上内容供参考,如有问题还望指出。

你可能感兴趣的:(文件)