我们公司是最第三方支付公司,最近为了避免资源被频繁点击下次造成性能上的压力,考虑下载excel用同步的的形式,就是一次点击下载,按钮变灰,要当前下载完才能正常点击,下载用ajax方式怎么实现同步啊,谢谢大家,祝大家工作顺利。
我们用如下方式好像同步不了
jsp 页面:
$.ajax({
cache: true,
type: "POST",
url:ajaxCallUrl,
data:$('#yourformid').serialize(),//这个form就是我下载excel的地址
async: false,
error: function(request) {
alert("下载失败");
},
success: function(data) {
alert("下载成功");;
}
});
springMVC后台返回流:
/*
*游览器左下角下载
*/
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename="
- "EXCEL.xls");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
byte[] ba = bos.toByteArray();
bos.close();
in = new ByteArrayInputStream(ba);
HSSFWorkbook xwb = (HSSFWorkbook) WorkbookFactory.create(in);
out = response.getOutputStream();
xwb.write(out);
out.flush();
//--------end-----------
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
**