File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes PDF filename problem,URGENT!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "PDF filename problem,URGENT!!!" Watch "PDF filename problem,URGENT!!!" New topic

PDF filename problem,URGENT!!!

Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
i want to show my PDF file on browser.
i am using servlet.
now the problem is i want to set the defualt file name when user clicks save as....

String finFileName=t+"-"+timeValFin+".xls";

//diaplying SAVE AS DIALOG
res.setHeader( "Content-Disposition","inline; filename="+ finFileName);
String realPath = this.getServletContext().getRealPath("");

FileInputStream in = new FileInputStream(fileName+".xls");
ServletOutputStream out = res.getOutputStream();
byte[] buf = new byte[1024];
int read = -1;
while ( (read =, 0 , 1024)) != -1)
out.write(buf, 0, read);

this is my code i am using...
now when i press save as button the defualt filename which i specified is not coming instead its taking serrvlet name as filename...
what is the problem in the code.
please help me...
thank you.
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5382
why dont you simply forward to the URI of your XLS file, if no security issues are there or file is not being generated at runtime.

"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Nikki Aniban

Joined: Oct 10, 2002
Posts: 14
Hi Sejal!
The filename parameter must be enclosed in double quotes.
Try using this:
res.setHeader( "Content-Disposition","inline; filename=\""+ finFileName + "\";");
Hope this helps!
p.s. and if you want to force the Save As Dialog box to appear, you should use "attachment" as the Content-Disposition instead of "inline"
- Nikki
[ September 21, 2003: Message edited by: Nikki Aniban ]
I agree. Here's the link:
subject: PDF filename problem,URGENT!!!
It's not a secret anymore!