前端html 通过文件流下载文件
后台返回文件流方式,前端采用form表单 action 属性赋值流。代码submit提交.
前端代码如下:
<form id="download" action='' method='post'/>
</form>
$("#download").attr("action", url);
//触发submit事件,提交表单
$("#download").submit();
后台java 代码如下
response.reset();
response.setContentType("application/vnd.ms-excel");//excel表格
response.setHeader("Content-disposition", "attachment;filename=" +
new String((filename + 后缀名).getBytes(),
"iso-8859-1"));
OutputStream ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();