没啥好说的。关键代码:
// Set the headers. res.setContentType("application/x-download");
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
// Send the file. OutputStream out = res.getOutputStream( );
returnFile(filename, out); // Shown earlier in the chapter
3. Microsoft documents Internet Explorer's deviant behavior, although I've found that reality doesn't exactly match the documentation.
4. The HTTP specification recommends setting the Content-Type to application/octet-stream. Unfortunately, this causes problems with Opera 6 on Windows (which will display the raw bytes for any file whose extension it doesn't recognize) and on Internet Explorer 5.1 on the Mac (which will display inline content that would be downloaded if sent with an unrecognized type).
文件名问题就以url来做。上面英文中 有提到。
http://onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html#ex3-9