jsp
<form id="Form1" action="#" >
<table cellspacing="0" cellpadding="0">
<tr>
<td width="5%" class="query_label">年:</td>
<td class="query_data" width="10%">
<select id="year" name="year" style="width:70px;">
<option value="">请选择</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
</select>
</td>
<td width="5%" class="query_label">月:</td>
<td class="query_data" width="10%">
<select id="month" name="month" style="width:70px;">
<option value="">请选择</option>
<option value="1">1 </option>
<option value="2">2 </option>
</select>
</td>
<td><a class='easyui-linkbutton' href='#' onclick="doBillExport1();">下载</a></td>
</tr>
</table>
</form>
//导出 判断下载文件是否存在
function doBillExport1(){
var year=$("#year option:selected").val();
var month=$("#month option:selected").val();
$.ajax({
type: "POST",
cache:false,
url: "${ctx}${arPath}/aaa/download1",
data:{'year':year,'month':month},
dataType: "json",
success: function(data){
if(data==1){
layer.alert("该月份文件不存在!!");
}else{
doBillExport12(); 存在调用
}
}, //回调失败,本次请求超时
error: function () {
alert("请求超时");
}
});
}
// 下载文件调用
function doBillExport12() {
$("#Form1").attr("action", "${ctx}${arPath}/aaa/download").removeAttr("onsubmit");
$("#Form1").submit();
}
java
@RequestMapping(value = "/download1" , method = RequestMethod.POST)
@ResponseBody
public String download1( String year,String month) throws IOException {
String lastDay= getFileExist(year, month);//获取年月日
String filePath = "D:\\excel\\信息"+lastDay+".xlsx";
AR_TAX_BILL_LOGGER.info("名称:{}", filePath);
File resourceFile = new File(filePath);
if (!resourceFile.exists()) {
AR_TAX_BILL_LOGGER.info("名称:{},不存在", filePath);
return "1";//文件不存在
}else{
return "2";//存在
}
}