Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PDF filename problem,URGENT!!!

 
Hd Desai
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
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.setStatus(res.SC_OK);
res.setContentType("application/vnd.ms-excel");
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 = in.read(buf, 0 , 1024)) != -1)
{
out.write(buf, 0, read);
}
out.flush();
out.close();

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
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nikki Aniban
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic