how to force download of file from website

Posted on 2011-09-07
Last Modified: 2012-06-27
I am trying to create a jsp program to force the "download" dialog, not open the file in the user's browser. I'm having trouble. I have the following code, but it opens the file in the browser anyway. The file is just an Automated Clearing House transaction file which the user has to save to a special location, so there is little sense (an preferable NOT) to see the file contents. What can I do?

<%@page trimDirectiveWhitespaces="true"%>
    response.setHeader("Content-disposition", "attachment; filename=ACH.txt");

%><%@ page import="*"%>
out.println("101 .... etc\r);
out.println(" .... ");
Question by:jmarkfoley
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 14

Accepted Solution

brendanmeyer earned 500 total points
ID: 36500417
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"filenamehere.mp3\");

Open in new window


Author Comment

ID: 36500488
Ooooh! interesting. I actually got it working using


but I think I like yours better. Did you make that up or is it a real ContentType? I don't see it listed in, but that list could be old.
LVL 14

Expert Comment

ID: 36500498
i found it on the website linked, but there would be a lot more content types then listed on that page, and new files types are created all the time

Author Closing Comment

ID: 36507364

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse with various Java releases 7 53
CSS Style 8 43
Timer on div 5 26
Tomcat 9 + java 8 error while trying to deploy a war file 2 734
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question