当我下载签名的pdf文件时,它被Adobe Reader显示为无效。我可以在我的本地项目文件夹中的服务器上正常查看此文件,但是当我通过我的servlet下载该文件的过程时,在此下载过程中的某些内容使得pdf无效。 这是我的servlet下载代码:
response.setContentType("application/pdf");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-Disposition","inline;filename=CompensationReport" + compensation+".pdf");
response.setHeader("Accept-Ranges", "bytes");
FileInputStream fis = new FileInputStream(thePdf1);
BufferedInputStream bis = new BufferedInputStream(fis);
ServletOutputStream sos = response.getOutputStream();
byte[] buffer = new byte[2048];
while (true) {
int bytesRead = bis.read(buffer, 0, buffer.length);
if (bytesRead < 0) {
break;
}
sos.write(buffer, 0, bytesRead);
sos.flush();
}
sos.flush();
bis.close();
return;