Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Renaming the file while saving

 
Naga Reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you

It is working fine now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic