public ActionForward createExcelByGdJianXiuModList(String formIds) {
GdJianXiuDao gdjianxiuDao = (GdJianXiuDao) SpringContextUtils.getBean("gdjianxiuDao");
String form_name = new Long(new Date().getTime()).toString();
String modeExcelWebRoot = request.getSession().getServletContext().getRealPath("/");
String temp = modeExcelWebRoot;
modeExcelWebRoot = temp + "filedata/jianxiu";
OutputStream out = null;
String path = "";
path = modeExcelWebRoot + "/某某.xls";
while (temp.indexOf("\\") != -1) {
temp = temp.replace('\\', '/');
} FileInputStream fileIn = null;
try {
fileIn = new FileInputStream(path); HSSFWorkbook wb = new HSSFWorkbook(fileIn);
ModifyExcel m = new ModifyExcel(); String excelName = form_name + ".xls";
String s_attachment = "attachment; filename=" + excelName;
s_attachment = new String(s_attachment.getBytes("gb2312"), "ISO8859-1");
String[] arrformIds = formIds.split(","); for (int i = 0; i < arrformIds.length; i++) {
int formid = Integer.parseInt(arrformIds[i]);
GdJianXiuMod gdjianxiumod = gdjianxiuDao.selectJianxiu(formid);
m.modify(wb, i + 1, 0, i + 1 + ""); //序号
m.modify(wb, i + 1, 1, gdjianxiumod.getAppid() + " ");
m.modify(wb, i + 1, 2, gdjianxiumod.getAppdepartment() + " ");
}
// ===================================增加页脚 -===========================
HSSFSheet sheet = wb.getSheetAt(0);
HSSFFooter footer = sheet.getFooter();
footer.setCenter("Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages());
response.setHeader("Content-disposition", s_attachment); // 设定输出文件头
response.setContentType("application/vnd.ms-excel");// 定义输出类型
response.setContentType("text/html;charset=GBK"); out = response.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(out); wb.write(bos); out.flush();
out.close();
fileIn.close();
} catch (Exception e) {
e.printStackTrace();
}
ActionForward actionForward = new ActionForward("/gdtmis/jianxiu/statistic/excelSuccesc.jsp");
return actionForward;
}
上面代码是处理excel下载的,数据是查询页面传递过来的,
下载按钮跟查询按钮在同一个页面
在页面点击下载按钮,正常下载完后,
再设置条件点击查询按钮时,下载对话框又出现了,
我估计是out = response.getOutputStream();没有关掉,
请高手指点一下怎么才能关掉out = response.getOutputStream();
GdJianXiuDao gdjianxiuDao = (GdJianXiuDao) SpringContextUtils.getBean("gdjianxiuDao");
String form_name = new Long(new Date().getTime()).toString();
String modeExcelWebRoot = request.getSession().getServletContext().getRealPath("/");
String temp = modeExcelWebRoot;
modeExcelWebRoot = temp + "filedata/jianxiu";
OutputStream out = null;
String path = "";
path = modeExcelWebRoot + "/某某.xls";
while (temp.indexOf("\\") != -1) {
temp = temp.replace('\\', '/');
} FileInputStream fileIn = null;
try {
fileIn = new FileInputStream(path); HSSFWorkbook wb = new HSSFWorkbook(fileIn);
ModifyExcel m = new ModifyExcel(); String excelName = form_name + ".xls";
String s_attachment = "attachment; filename=" + excelName;
s_attachment = new String(s_attachment.getBytes("gb2312"), "ISO8859-1");
String[] arrformIds = formIds.split(","); for (int i = 0; i < arrformIds.length; i++) {
int formid = Integer.parseInt(arrformIds[i]);
GdJianXiuMod gdjianxiumod = gdjianxiuDao.selectJianxiu(formid);
m.modify(wb, i + 1, 0, i + 1 + ""); //序号
m.modify(wb, i + 1, 1, gdjianxiumod.getAppid() + " ");
m.modify(wb, i + 1, 2, gdjianxiumod.getAppdepartment() + " ");
}
// ===================================增加页脚 -===========================
HSSFSheet sheet = wb.getSheetAt(0);
HSSFFooter footer = sheet.getFooter();
footer.setCenter("Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages());
response.setHeader("Content-disposition", s_attachment); // 设定输出文件头
response.setContentType("application/vnd.ms-excel");// 定义输出类型
response.setContentType("text/html;charset=GBK"); out = response.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(out); wb.write(bos); out.flush();
out.close();
fileIn.close();
} catch (Exception e) {
e.printStackTrace();
}
ActionForward actionForward = new ActionForward("/gdtmis/jianxiu/statistic/excelSuccesc.jsp");
return actionForward;
}
上面代码是处理excel下载的,数据是查询页面传递过来的,
下载按钮跟查询按钮在同一个页面
在页面点击下载按钮,正常下载完后,
再设置条件点击查询按钮时,下载对话框又出现了,
我估计是out = response.getOutputStream();没有关掉,
请高手指点一下怎么才能关掉out = response.getOutputStream();
bos没关吧