Solved

how to force download of file from website

Posted on 2011-09-07
4
435 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 53
Is there an event to update the text when user types in textbox? 6 41
Getting Column Height to Match Other Column 5 44
Split in Javascript 5 30
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

930 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