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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
Similar Threads
Downloading a multiple file from server
problems with microsoft excel driver
Saving JSP output to a File with extension .xls
Uploading xls files with JSF
Export data from Jsp to Excel taking more load time