Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

specifying pdf document's name in browser - content-disposition problem

843842Sep 25 2008 — edited Sep 29 2008
Hello ,
I want to open a PDF document in browser, which needs to have a specified filename when user tries to save it.
My web app sends an "application/pdf" document back to the browser.
I use the Content-Disposition HTTP header to instruct the browser to open the document inline, i.e. using the appropriate plugin, which is Adobe PDF in this case. When the user clicks Save As..., the document filename needs to be the one specified by the same HTTP header. Here is the code:
response.setContentType("application/pdf");
String contentDisposition = "inline; filename=\"filename.pdf\"";
response.setHeader ("Content-Disposition", contentDisposition);
response.setHeader ("Content-Length",new Long(file.length()).toString());
Unfortunately this does not work for me. Document opens fine, but I can't get it to have the name I specified. The plugin uses the default name, which is the full URL of the document. I tried several combinations of HTTP headers, but neither worked. I tried putting an additional GET request parameter at the end of the URL, like ...&filename=filename.pdf , but that didn't work either.
I tried Adobe 7.0 and 8.1.2.

Any suggestions ?

Thanks a lot!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2008
Added on Sep 25 2008
5 comments
2,260 views