0

I am hosting a simple html file on localhost, I want to force google chrome browser to download file instead of opening it. For the same I've used download attribute in anchor tag, but it is not supported yet.

Is there any setting in Apache Tomcat 8 for adding some thing in HTTP response header for that particular file.

<div><a href="mpo.mpo" download>Image mpo file type</a></div>
jww
  • 97,681
  • 90
  • 411
  • 885
Vivek Kumar
  • 4,822
  • 8
  • 51
  • 85

1 Answers1

1

Did you try setting these headers in the response:

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=file.ext");

If you really haven't created any kind of servlet/controller to receive the request you might need to configure a filter: http://tomcat.apache.org/tomcat-8.0-doc/config/filter.html

You can find a lot of information here too: Set CORS header in Tomcat

Community
  • 1
  • 1
eduardohl
  • 1,176
  • 2
  • 10
  • 23
  • I haven't created any servet. I just have place some html file inside apache installation dir. "C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\ROOT\v" – Vivek Kumar Jan 15 '15 at 02:49
  • I guess there is some default webapp, I will appreciate if you please tell me where I have to put these response setting. I mean the file where I need to put your suggested changes – Vivek Kumar Jan 15 '15 at 02:50
  • I am confused seeing the web.xml file! can you please tell me correspoind filter for esponse.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=file.ext"); for png file type – Vivek Kumar Jan 15 '15 at 03:31