1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
DocumentException ex = null;
ByteArrayOutputStream baosPDF = null;
try {
if(1==1)
throw new ServletException("testr");
baosPDF = generatePDFDocumentBytes(request, this
.getServletContext());
StringBuffer sbFilename = new StringBuffer();
sbFilename.append("Report");
sbFilename.append(".pdf");
response.setHeader("Cache-Control", "max-age=30");
response.setContentType("application/pdf");
StringBuffer sbContentDispValue = new StringBuffer();
sbContentDispValue.append("attachment");
sbContentDispValue.append("; filename=");
sbContentDispValue.append(sbFilename);
response.setHeader("Content-disposition", sbContentDispValue
.toString());
response.setContentLength(baosPDF.size());
ServletOutputStream sos;
sos = response.getOutputStream();
baosPDF.writeTo(sos);
sos.flush();
}catch(ServletException se){
throw se;
}
catch (DocumentException dex) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (baosPDF != null) {
baosPDF.reset();
}
}
} |
Partager