Link to home
Start Free TrialLog in
Avatar of Mark
Mark

asked on

how to force download of file from website

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(" .... ");
%>
ASKER CERTIFIED SOLUTION
Avatar of Brendan M
Brendan M
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark
Mark

ASKER

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.
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
Avatar of Mark

ASKER

Thanks!