browser « PDF « JSP-Servlet Q&A

1. How to change the title of a browser page which a servlet streamed a PDF to?

My Java based webapp has a servlet which streams PDF content back to the browser based on request parameter. e.g. user clicks on an A tag with an href of "myApp/FetchPDFServlet?id=123". Servlet ...

2. Set filename of the Pdf that is streamed back to the browser

I have a Java webapp creating a pdf and streaming it back to the browser.

 byte[] pdf = report.exportPdfToArray(user);
response.setHeader("content-disposition", "inline; filename=\"My.pdf\"");
outStream = response.getOutputStream();
The report is executed and it is sent ...

3. Pdf opens blank in browser

You should put this in a servlet, not a JSP, JSPs have too many things happening behind the scenes (if you check your error logs you may find some of them). Example: You probably get an error when you use response.getOutputStream() since for a typical JSP the response.getWriter() has already been called and you aren't allowed to call both. You tell ...