Download example

xiaoxiao2021-03-06  47

<% @ page import = "java.io. *;"%> <% try {string URL = "d: /websrc/aaa.doc"; // actual file path string name = "default Chinese file name .doc" ; // Display the file name to the user, that is, IE pop-up download box prompts save the file name response.reset (); response.setContentType ("bin"); response.setheader ("Content-Disposition", Attachment; Filename = " new string (name.getbytes ()," ISO8859-1 ")); // Processes Chinese issues for the default file name

ServletOutputStream Os = response.getOutputStream (); fileinputstream in = new fileinputstream (URL); byte [] data = new byte [1024]; int Temp = -1; while ((Temp = in.read (data))! = - 1) {Os.Write (DATA, 0, TEMP); Os.Flush ();} // While // In.close (); os.close ();} catch (exception e) {Out.print (E .tostring ());}%>

Common MIME type

Hypertext markup language text.html, .html text / html normal text.txt text / plain RTF text.rtf Application / RTF GIF graphic .gif image / gif JPEG graphic.ipeg, .jpg image / jpeg au sound file .au Audio / Basic Midi music file MID, .MIDI AUDIO / MIDI, AUDIO / X-MIDI REALAUDIO Music file .ra, .ram audio / x-pn-realaudio mpeg file. mpg, .mpeg video / mpeg avi file .avi video / x -msvideo gzip file .gz Application / X-Gzip Tar file .tar Application / X-TAR

转载请注明原文地址:https://www.9cbs.com/read-116153.html

New Post(0)