1.jsp代码
<%
String exportToExcel = request.getParameter("exportToExcel");
if (exportToExcel != null
&& exportToExcel.equalsIgnoreCase("YES")) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename="
+ "excel.xls");
}
String sdeptCode = request.getParameter("sdeptCode");
String smallUnitType2 = request.getParameter("smallUnitType2");
String isSum = request.getParameter("isSum");
%>
<%
if (exportToExcel == null) {
%>
<a id="importExcel">导出表格至Excel</a>
<%
}
%>
2.js控制动态标签
<script type="text/javascript">
$(function () {
var sdeptCode = "<%=sdeptCode %>";
var smallUnitType2 = "<%=smallUnitType2 %>";
var isSum = "<%=isSum %>";
if (sdeptCode == "null") {
sdeptCode = '';
}
if (smallUnitType2 == "null") {
smallUnitType2='';
}
if (isSum == "null") {
isSum = '';
}
$("#importExcel").attr("href","first.htm?exportToExcel=YES&sdeptCode=" + sdeptCode + "&smallUnitType2=" + smallUnitType2 + "&isSum=" + isSum);
})
</script>
效果图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200319150501765.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjI5Mzc4OQ==,size_16,color_FFFFFF,t_70)