How to download file in Servlet?
Edward King <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <00b001c3fcda$b2e50750$922aa8c0@sky> |
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