This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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
problems with microsoft excel driver
Export data from Jsp to Excel taking more load time
Saving JSP output to a File with extension .xls
Uploading xls files with JSF
Downloading a multiple file from server