我正在尝试开发一个函数,以便使用JSF导出CSV文件。这是我开发的代码
StringBuilder cardReport = getCoreService().createCardReport(cardType.getId());
HttpServletResponse response = (HttpServletResponse) WebFlowUtils.getExternalContext().getNativeResponse();
response.setContentType("text/comma-separated-values; charset=utf8");
byte[] buffer = cardReport.toString().getBytes();
response.setContentLength(buffer.length);
response.getOutputStream().write(buffer);
response.setHeader("Content-Disposition", "attachment;filename=\"report.csv\"");
response.getOutputStream().flush();
response.getOutputStream().close();
WebFlowUtils.getExternalContext().recordResponseComplete();
问题是每次导出结果时,都会在文件内容的末尾插入一个冗余的</html>
标记。此外,我的内容根本不是HTML相关的。当我调试代码时,我看到html标签不存在,它将在导出时插入。我该如何解决这个问题?