JSPSMARTupload upload download full Raiders (four)

xiaoxiao2021-03-18  199

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> <meta http-equiv =" content-type "content =" text / html; charSet = GB2312 "> </ head> <body> <a href="jsp/do_download.jsp"> Click to download </a> </ 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.</p> <p>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 <l) {int j = fileinputstream.read ( Abyte0, 0, i); k = j; m_response.getOutputStream (). Write (Abyte0, 0, j);</p> <p>} 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 <s.length (); i ) {char C = S.Charat (i); if (c> = 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 <B.Length; J ) {INT K = B [J]; IF (k <0) k = 256; sb.append ("%" integer.tohexstring (k) .touppercase ());}}} Return Sb.toString ();} The medium bold part, the original JSPSMARTupload component does not work on the returned file, and now, the encoded conversion work is now converted to the form of the UTF-8 form. UTF-8 encoding does not make any processing in English, and it needs to be converted to% XX in English. In the TOTF8String method, the UTF-8 encoding of the Chinese character character is obtained directly by the encoding conversion method provided by the Java language, and then converted to% XX. After compiling the source code to jspsmartupload.jar, copy to Tomcat's Shared / Lib Directory (can be shared by all web applications), then restart the Tomcat server, you can download files containing Chinese names. In addition, Toutf8String methods can also be used to convert hyperlinks containing Chinese to ensure the valid link of the link, because some web servers do not support Chinese links. Summary: JSPSMARTupload component is the Upload Download Components that use JSP for the B / S program development process, which is simple and convenient to use. Now I have the support of the document that downloads Chinese names. It is like a tiger to add more popularity.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-130018.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="130018" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.036</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'w_2Fb4ZnmA4_2F4EcVBLtfzyjF0hk3xHT5NYgRVtqCeYlSu2iAilCwNvqGfcc5Xw02kzZ9L9YxnOWvwUitVR4cAg5w_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>