JSP导出报错:getOutputStream() has already been called for this response

必须要有这个部分:
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
 response.reset();
	response.setContentType("application/vnd.ms-excel; charset=utf-8");
	response.setHeader("Content-Disposition",
			"attachment;Filename=ResultReport.xls");
	OutputStream outputStream = null;
	try {
		outputStream = response.getOutputStream();
		HSSFWorkbook hssfWorkbook = GenDataUtil.genData(listData,
				listMetaObjectProperty);
		hssfWorkbook.write(outputStream);
		outputStream.flush();
		outputStream.close();
	} catch (Exception e) {
		System.out.print("导出Excel发生错误,信息:" + e);
	} finally {
     response.flushBuffer();
		out.clear();
		out = pageContext.pushBody();
		outputStream = null;
		listData = null;
		listMetaObjectProperty = null;
	}

你可能感兴趣的:(jsp,Excel)