• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Renaming the file while saving

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you

It is working fine now
reply
    Bookmark Topic Watch Topic
  • New Topic