aspose file tools*
The moose likes JSP and the fly likes Renaming the file while saving Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Renaming the file while saving" Watch "Renaming the file while saving" New topic
Author

Renaming the file while saving

Naga Reddy
Greenhorn

Joined: Aug 22, 2006
Posts: 4
Hi,

I wrote the following code to open an xls file in a jsp file called (Test.jsp)

response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma","no-cache");
ServletOutputStream stream = response.getOutputStream();
InputStream streamIn = new FileInputStream("d:\hi.xls");
int data = 0;
while((data = streamIn.read()) != -1)
{
stream.write(data);
}
streamIn.close();
stream.flush();
stream.close();

The code is working fine but while saving the xls file instead of saving like hi.xls it is saving as Test.xls where Test is the jsp name

How can we directly save as hi.xls instead of Test.xls?

Pls help me in this regard

Thanxs in advance

Regards,
Naga Reddy
Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
Hi Naga,
The below line should allow you to give what ever name to the download file.
res.addHeader("Content-Disposition", "inline; filename=xyz.xls");

Hope this helps


Regards,
Sivaraman.L
Naga Reddy
Greenhorn

Joined: Aug 22, 2006
Posts: 4
Thank you

It is working fine now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Renaming the file while saving