This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Response Header for PDF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Response Header for PDF?" Watch "Response Header for PDF?" New topic

Response Header for PDF?

Ryan Forman

Joined: Sep 20, 2006
Posts: 1
I set the response header in my code as follows:

response.setHeader("Content-disposition", "attachment; filename=" + reportName);

If I remove "attachment" from the line above, the PDF will display in the browser. If I leave the code as-is, then the user is prompted to either save or view the PDF. If the user chooses to view the PDF, the PDF is displayed in Acrobat. I would like to find a middle ground. I would like to prompt the user to either save or view the PDF, however; if the user chooses to view the PDF, I would like to display it in the browser...not in seperate Acrobat. Is this possible? How? Thank you for the help.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
You can't. Either you force a save-as prompt like that or let the browser decide what to do.
In the latter case the browser will display the PDF in some way if it can (meaning it has a PDF reader plugin or built-in capability) and otherwise will prevent a prompt asking the user what to do.

PS, this has nothing at all to do with Java per se.

I agree. Here's the link:
subject: Response Header for PDF?
Similar Threads
Efficient Streaming Methods
Open file from JSP or Servlet in Acrobat reader
How can I download a file from a jsp?
When i try to open pdf, it shows 'There was an error opening this document.' message
Filename attribute for Inline Content-Disposition Meaningless?