• 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

downloading a file. how can i set the file name?

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a .zip file stored in my database in a BLOB field and I want my web site user to download this file when he/she clicks on a web page button. Here is what I do in my servlet:
response.setContentType("application/octet-stream");
byte[] b = /*get the BLOB field from my database*/
OutputStream out = response.getOutputStream();
out.write(b);
out.flush();
out.close();
When the user clicks on my web page button the above code is executed and my web browser prompts the user to download the file, but the dialog box displays the form action instead of the filename. The contents of the file are ok, but I want the user to be able to save the file with the same name as it is stored in the database.
Can anyone help me with this?
Att.
Leonardo Penha
P.S.: In my servlet I have the file name stored in a String variable.
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to set a Http Header called content disposition to set the file name which you can do as follows:
response.setHeader("Content-disposition", "inline;filename=<your filename here>"
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic