java代码:
final Map<String,Object> params = map;
final HttpSession session = request.getSession();
//TODO 开个线程用于生成xls
Thread threadStuBase = new Thread(){
public void run() {
//dosmothing
//statr...
session.setAttribute("state", "203");//203
try {
handleUploadData(params,downloadPath,zipDownloadPath);
} catch (Exception e) {
e.printStackTrace();
session.setAttribute("state", "201");//201
}
session.setAttribute("zipDownloadPath", zipDownloadPath);
session.setAttribute("state", "200");//200
//
//end
};
};
threadStuBase.start();
jsp 代码 :
//生成excel数据
var url="${ctx}/sms/archives/base/downloadTemplate?"+param;
$.ajax({
type: 'post',
url: url,
data:{},
dataType: 'json',
success:function(data){
$.singleLoading();
var timer = setInterval(function(){
var _url="${ctx}/sms/archives/base/checkDownloadTemplate";
$.ajax({
type: 'post',
url: _url,
data:{},
dataType: 'json',
success:function(data){
if(data.code == 200){
window.clearInterval(timer);
$.singleRemove();
//下载
var url = "${ctx}/sms/archives/base/uploadExcelData?zipDownloadPath="+data.zipDownloadPath;
window.location.href= url;
}else if(data.code == 201){
$.jBox.tip(data.msg, "info", {timeout: 1500});
window.clearInterval(timer);
$.singleRemove();
}
}
});
},2000);
}
});