File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

PDF filename problem,URGENT!!!

Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
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

Joined: Oct 15, 2001
Posts: 5370
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
Greenhorn

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: http://aspose.com/file-tools
 
subject: PDF filename problem,URGENT!!!
 
Similar Threads
Unzipping a .zip file containing .gif files
Urgent Help In Cryptogarphy.....JCE EXPERTS PLZ HELP
URGENT...HELP IN JCE
URGENT:NEED HELP IN JCE
URGENT.HELP FROM CRYPTOGRAPHY EXPERTS IN JCE