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

Renaming the file while saving

Naga Reddy

Joined: Aug 22, 2006
Posts: 4

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

ServletOutputStream stream = response.getOutputStream();
InputStream streamIn = new FileInputStream("d:\hi.xls");
int data = 0;
while((data = != -1)

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

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

Naga Reddy

Joined: Aug 22, 2006
Posts: 4
Thank you

It is working fine now
I agree. Here's the link:
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