Fourth, the file download articles 1, download links page download.html page source code as follows: <- filename:! Download.html Author: vertical and horizontal software production center rain also odd (zhsoft88@sohu.com) ->
Download title> head> Click to download body> html> 2, download processing page do_download.jsp do_download.jsp show How to use the JSPSMARTupload component to download files, you can see from the source code below, and how simple downloads are downloaded. The source code is as follows: <% @ page contenttype = "text / html; charset = GB2312" import = "com.jspsmart.upload. *"%> <% // New a smartupload object Smartupload Su = new smartupload (); // Initialization Su.initialize (PageContext); // Sets ContentDisPosition to NULL to prohibit the browser to automatically open the file, // guarantees that you click the link after downloading. If not set, the downloaded file extension is // DOC, the browser will automatically open it with Word. When the extension is PDF, // The browser will open with Acrobat. Su.SetContentDisPosition (NULL); // Download file Su.downloadfile ("/ UPLOAD / How to earn my first bucket gold.doc");%> Note, perform downloaded pages, outside the Java script (ie < % ...%>, do not include characters such as HTML code, space, carriage return, and wrap, and some will not download correctly. If you don't believe it, you can add a newline character in the above source code, and then download it, and ensure an error. Because it affects the data stream returned to the browser, it causes the parsing error. 3, how to download Chinese files JSPSMARTupload although files can be downloaded, it is insufficient to support Chinese. If there is Chinese characters in the downloaded file name, the browser shows a bunch of garbled when prompted the file name, which is very sweeping. The above example is this. (This problem is also the problem exists in many download components. Few people solve, search for relevant information, sigh!) In order to add support for the JSPSmartupLoad component to download Chinese files, I have studied the component and found it back to return. After the Six Save File Name of the browser is UTF-8 encoding, the browser can display the Chinese name correctly. This is a delighted discovery.
So I made of SmartUpload class jspSmartUpload components of the upgrade process, increase toUtf8String this method, alter some source code as follows: public void downloadFile (String s, String s1, String s2, int i) throws ServletException, IOException, SmartUploadException {if (s == NULL) Throw new ILLEGALARGUMENTEXCEPTION ("File '" S "' Not Found (1040)."); if (S.Equals (")) Throw new IllegalGumentException (" File ' S "' NOT Found (1040). "); if (! isvirtual (s) && m_denyphysicalpath) throw new securityException (" Physical path isdenied (1035)); if (isvirtual (s)) s = m_application.getRealPath (s); Java .io.file file = new java.io.file (s); fileinputstream fileinputstream = new fileinputstream (file); long L = file.Length (); boolean flag = false; int K = 0; byte Abyte0 [] = new BYTE [I]; if (S1 == NULL) m_response.setContentType ("Application / X-MSDownload"); Elseif (S1.Length () == 0) m_response.setContentType ("Application / X-MSDownload"); Elsem_Response .SETCONTENTTYPE (S1); M_RESPONSE.SETCONTENTLENGTH ((int)); m_contentdisposition = m_contentdisposition! = null? m_contentdisposition: "attachment ; "; if (S2 == NULL) m_response.sethead (" Content-Disposition ", M_ContentDisPosition " FileName = " Toutf8String (GetFileName (S))); Elseif (S2.Length () == 0) m_response.setHeader ( "Content-Disposition", m_contentDisposition); elsem_response.setHeader ( "Content-Disposition", m_contentDisposition "filename =" toUtf8String (s2)); while ((long) k
} fileinputstream.close ();} / *** convert the Chinese characters in the file name into the UTF8 encoded string to download the saved file name correctly when downloaded. * Crossing software production center rain also 2003.08.01 * @Param S original file name * @return Recode file name * / public static string Toutf8String (string s) {stringbuffer sb = new stringbuffer (); for (int i = 0; i = 0 && c <= 255) {sb.append (c);} else {byte [] b; try {b = character.tostring (c) .getbytes "UTF-8");} catch (exception ex) {system.out.println (ex); b = new byte [0];} for (int J = 0; j