Share this page 

Handle PDF outputTag(s): Servlet/JSP


  • Set the content-type of the response to "application/pdf", ex. response.setContentType("application/pdf");
  • Add a dummy parameter on the end of the url, like:
    http://x.y.z/DoGenCompStmt?filename=dummy.pdf
    because IE ignores content-types, so you need to give it a hint, and the ".pdf" extension is an easy way.
  • Set the "content-length" on the response, otherwise the Acrobat Reader plugin may not work properly, ex. response.setContentLength(bos.size());
  • An additional thing that seems to help some IE browsers is to also have : response.setHeader("Content-Disposition", "inline;filename=somepdf.pdf");