Solved

how to force download of file from website

Posted on 2011-09-07
4
439 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
[X]
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
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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 …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

705 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