This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Title as PDF file name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Title as PDF file name" Watch "Title as PDF file name" New topic

Title as PDF file name

v su

Joined: Mar 20, 2008
Posts: 2
I want to save the PDF file with the PDF title as name, but its saved as my servlet name.
My servlet ( code as below

String filePath = "C:\report\MyPDF.gzip";
FileChannel fcin = new FileInputStream(filePath).getChannel();
BufferedInputStream bis = new BufferedInputStream( new GZIPInputStream(new BufferedInputStream(Channels.newInputStream(fcin))));
BufferedOutputStream bos = new BufferedOutputStream(new GZIPOutputStream(response.getOutputStream()));
response.setHeader("Vary", "Accept-Encoding");
response.setHeader("Content-Disposition", "inline; filename=MyReport.pdf");
for (int i=0; i<1; ++i)
bytesRead =, 0, bufferSize);
if( bytesRead ==-1 ) break;
bos.write(buff, 0, bytesRead);


While saving my report it is saved as report.pdf
Pls help me regarding this.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42371
Welcome to JavaRanch.

Instead of a disposition of "inline", use "attachment".

Ping & DNS - my free Android networking tools app
v su

Joined: Mar 20, 2008
Posts: 2
If I changed to Attachment means, its working fine, but I want to display in same page thats why i put inline.

subject: Title as PDF file name