这是我的代码,fileByte在一个数组中,其中包含PDF的内容。但是,该文件已损坏,我无法从中读取。这里出了什么问题?谢谢!
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.addHeader("Content-Disposition", "attachment;filename=test.pdf");
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(fileByte.length);
outputStream.write(fileByte);
outputStream.flush();
outputStream.close();
检查这个:
发送pdf到http客户端
首先确保您有正确的字节,因此尝试将其写入文件并验证字节数组是否正确。一旦您完成了这些,那么将其写入输出流以获得http响应应该是好的。
希望有帮助!