JSP 表单提交
动作="PDFServlet" 方法="发布"
SERVLET 代码
从 byte[] 读取到 ServletOutputStream
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File file = new File("estatement.pdf");
ServletOutputStream stream = null;
BufferedInputStream buf = null;
try {
stream = response.getOutputStream();
// set response headers
response.setContentType("application/pdf");
response.setDateHeader("Expires", 0);
response.addHeader("Content-Disposition",
"inline; filename=estatement.pdf");
response.setContentLength((int) file.length());
buf = new BufferedInputStream(new FileInputStream(file));
int readBytes = 0;
while ((readBytes = buf.read()) != -1)
stream.write(readBytes);
} finally {
if (stream != null)
stream.flush();
stream.close();
if (buf != null)
buf.close();
}
}