Solved

how to force download of file from website

Posted on 2011-09-07
4
434 Views
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");
    response.setContentType("text/plain");

%><%@ page import="java.io.*"%>
<%
out.println("101 .... etc\r);
out.println(" .... ");
%>
0
Comment
Question by:jmarkfoley
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

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

Open in new window

from
https://www.vbulletin.com/forum/showthread.php/70959-HTTP-Headers-to-force-file-to-download-rather-than-auto-open
0
 
LVL 1

Author Comment

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

response.setContentType(\"text/x-setext\");

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 http://www.utoronto.ca/web/htmldocs/book/book-3ed/appb/mimetype.html, but that list could be old.
0
 
LVL 14

Expert Comment

by:brendanmeyer
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
0
 
LVL 1

Author Closing Comment

by:jmarkfoley
ID: 36507364
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now