• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

PDF filename problem,URGENT!!!

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic