Mr. King - Earlier versions of IE (5.5 and earlier) will display a text
file instead of downloading it (Microsoft doesn't care much about
Internet standards). But if you are using a newer version of IE, you
don't want a content type of multipart/form-data if you mean for the
browser to pop up the "save as" dialog. Try this instead:

response.setContentType("application/octet-stream");

There is a sample "download file application" with source code that can
be downloaded with JOT Servlets - http://www.jotobjects.com

Paul Copeland
JOT Servlets - A Framework for Servlet Applications

Date:    Fri, 27 Feb 2004 10:37:52 +0800
From:    Edward King <[EMAIL PROTECTED]>
Subject: How to download file in Servlet?

This is a multi-part message in MIME format.

--Boundary_(ID_smn+07iMEJvecH9oGhnCRw)
Content-type: text/plain; charset=gb2312
Content-transfer-encoding: 7BIT

I am trying to use a servlet to download an text file to the client from server,File located c:\1.txt in Server,when user explore this page,IE reminder user if download file "1.txt".I write following code.But when I explore this page,IE didn't remind me if download file and it didn't domnload file at all.How to correct following code to realize automatically download? What errors is in my code?

public void doPost(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException {
    response.setContentType("multipart/form-data");
    String file_name=new String("c:\\1.txt");
    String data=new String("data");
    response.setHeader("Content-Disposition","attachment;filename="+file_name);
    PrintWriter out = response.getWriter();
    out.println(file_name);
}

Thanks


___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to