On Friday 27 February 2004 03:09, Edward King wrote:
> I want to realize file automatically function.File located
> c:\1.txt,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(CONTENT_TYPE);
> String file_name=new String("c:\\1.txt");
>
> response.setHeader("Content-Disposition","attachment;filename="+file_
>name); PrintWriter out = response.getWriter();
> out.println(data);
> }
>
> Thanks in advances!
> Edward
I have a sample Servlet (sources included) available from my site
under
http://www.christianbollmeyer.de/dl?downloadFile=DownloadServlet.war
which should contain everything desired, including GZip compression.
Considering the code example given: out is a Writer, a text stream.
For delivering binary contents, you have to use another kind of
stream (the exact flavor depends on whether it's compressed,
buffered and the like). The sources should tell you all you need
to know about these matters.
HTH,
-- Chris (SCPJ2)
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com