HttpServletResponse response
ServletOutputStream out = null;
try {
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ";filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8"));
response.setContentType("application/octet-stream");
out = response.getOutputStream();
out.write(text.getBytes("UTF-8"));
out.flush();
out.close();
} catch (IOException e) {
log.error(fileName + ": 导出失败:", e);
throw new BusinessException("导出失败!");
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}