JSP Smartupload upload file garbled to solve the Documentary + UPLOADBEAN Upload Solution

xiaoxiao2021-03-06  33

Author: fbysss Disclaimer: This article is fbysss original. For reference, please indicate the author and reference Address Keyword: smartupload, uploadbean, linux, a Chinese garbled, SmartUpload upload files garbled solve the documentary nausea index: five-star level of completion: 80% ( File Name Questions Unresolved) Problem Description: WEB applications developed under Windows, use Smartupload upload files, very simple, is a form file formData.jsp, a file getData.jsp, debug, Windows and Linux systems are normal, and when the system is installed to another server, it has a problem that obtains a single parameter value is garbled (all question mark ???). The first feeling in my mind is: two machines, according to colleagues, it is the same disc installed Linux, but I think, according to logic inferior, it is definitely different, or the relevant service is different. Otherwise how can it? However, the task is given to me to solve it, and the system will be officially used immediately. If I ask for reinstall Linux, it is almost impossible. Well, I am not going to hell, who enters hell? I will put it. In fact, at this time, I also believe that the problem is not big. Because of the things developed by Java, garbled issues are home to the house, and the solution is that there are several. Isn't it a transcodation? At that time, the head asked me that my question is great. I said, there should be no big problem. I started to transfer getByte () transcoding, use ISO-8859-1 and GB312 / GBK "to transform, unregistered, and add UTF-8, no;" also "@ Page ContentType =" TEXT / HTML; Charset = GB2312 " > Code replacement, no; modify Linux lang = zh_cn.gb2312, not; modify the web.xml chars, no; I have almost all related to all related pages, and find this question and smartupload. But resolved There are very few people, and the solution to the solution is not detailed, so I posted on the 9CBS, the result is no one to pay attention to it, and there is no one in the top. I will develop groups. Everyone is busy, and I have no time to take care. Continue to debug your debugger, The result obtained by using System.GetProperty ("file.encoding") is ANSI_X3.4-1968, what code is this code? On the Google check, all useless information, at this time, I can't help but be cold ... nnd The problem is somewhat serious .. On the day, I didn't have a result. I have already felt, I don't want to overtake, but spending for a long time, I haven't got this "small problem", I really have a little, so I am Head is guaranteed, I will solve tomorrow. Back to the house, tea does not think about it. On QQ, talk to a mm, I said that I am tired today, she said that I can take a break tomorrow.

what? what day is it tomorrow? I can verify, rely, tomorrow, I am! It seems that God is destined to overtime on the weekend. I didn't sleep well at night, and I was a matter of a meal, or I still didn't have a good way. The next day, I got up at 11 o'clock, and the bowl of noodles began to dry, and the coding has been combined with new string (Str.GetByte ("ISO-8859-1"), "GBK"). No, what should I do, I see a solution to the Smartupload source code, I don't want to change the source code, because the server is remote, I don't have a root account, modify the class unable to restart. Progress 1: Remove the FormData.jsp in <% @ Page ContentTyPe = "Text / HTML; Charset = GB2312">, Plus After obtaining the page transcodation, it will be able to display Chinese normally. However, everyone knows that what is the consequence of this, Formdta.jsp can't display Chinese! This problem is more difficult to do, and there is no effect on the page with Response.setContentType, and the real evil door. Time is a little bit, I finally shaken, I started trying to remember the root password, I tried it, I am actually right. OK, I can finally flew. However, the source code of Smartupload is very bad, and there is no. I had to compile it. The result of using GEL is still different from others, it will change it, find the public void upload () in smartupload.java, add a parameter string charsetname, find this String S11 = New String (M_BinArray , m_startdata, (m_enddata - m_startdata) 1); modified to string S11 = new string (m_binarray, m_startdata, (m_enddata - m_startData) 1, charsetname); upload, restart and try again, and find a little progress. Progress 2: Partial parameters can be read correctly! This is only the value of the form text box, the file name is still garbled, I toss for a long time, I really don't want to get the source code of the smartupload, although there is not much code, but I have spent it so much. (Note: I think that the source code should be able to solve the problem, just not finished, the file name is needed to handle it. If you are interested, you can try it.) At this time, I naturally think of another upload package, search, some people say javazoom Good, do one, then say, Demo is very simple, then found, as long as the page GetData.jsp is transferred.

The transfer method can be a single parameter, you can use a sentence: Request.setCharacterencoding ("GBK"); at the same time, you should match MultipartFormDataRequest (Request, Null, 100 * 1024 * 1024, MultipartformDataRequest.cosparser, "GBK" "); This UPLOADBEAN is very considerate, actually provides a ChineseUpload.jsp example, in fact, the main two sentences are different. When I was modified, I feel almost 2 o'clock in the middle of the night. I want to relax, say anymore. On Sunday, continue to work, find a new problem, UPLOADBEAN actually cannot modify the uploaded file name! How does this? There is a variety of ways, each file creates a directory, then put it in preventing the renaming, but this is a bit disgusting, and the file name directly entering is still garbled, this is a good? ? ? Fortunately, I once again discovered the superiority of UploadBean, I found a post, say UploadBean 1.5 with Filemover can be renamed, so it has been 1.5 and filemover, and the example in FileMover is also very detailed. It's really intimate. . . Modify, upload restart, everything OK! Later, it was found that several related bugs of the system, a drum, all resolved. This "small problem", actually spent two days, but I am angry! At the same time, I also thought that the brothers who were like me, I can alleviate your pain, I am not white in these two days! My current slogan is: "About Smartupload, fully use Uploadbean". I also wrote a Demo to help the painful brothers solve the problem. Below, I put the Demo and the required information links I have been attached here. Everyone can communicate here with me.

Second, UPLOADBEAN Upload Solutions Satisfaction Index: Five Stars Edition: 100% Demo: 1. Table SSSformData.jsp <% @ Page ContentType = "Text / HTML; Charset = GB2312"%> FBYSSS UPLOADBEAN Example </ title> <! - Meta http-equiv = "content-type" content = "text / html; charSet = ISO-8859-1" -> <! - meta http-equiv = "content-type" Content = "text / html; charSet = GB2312" -> </ head> <form name = "form1" method = "post" action = "sssupload.jsp" encty = "multipleart / form-data"> <input name = "Title" type = "text" value = "Chinese words"> <TD class = "body"> attachment </ td> <td class = "bodyStyle"> <input name = "attach" type = "file" ID = "attach" size = "50"> </ td> <input name = "ok" type = "submit" value = "Submit"> </ form> 2. Read the form and upload the page SssUPload.jsp <! - // ================================================ =========================== // File: UPLOADBEAN Upload Instance // Function: Solve Chinese garbled, complete the file upload, and provide upload change solution // author: fbysss //msn:jameslastchina@hotmail.com // ================================ ===</p> <p>=========================================================== @ Page ContentType = "Text / html; charSet = GBK "%> <% @ page language =" java "import =" com.jspsmart.upload. * "%> <% @ Page Import =" java.text.SIMPLEDATEFORMAT "%> <% @ Page Import = "java.io.file"%> <% @ page import = "java.util. *"%> <% @ page import. * "%> <% @ page import =" UploadUtilities. Filemover "%> <head> <meta http-equiv =" content-type "content =" text / html; charset = GB2312> </ head> <% request.setcharacterencoding ("gbk"); // Setting the encoding format If you don't have to transfer one by one. FileMover filemover = new filemover (); // You can also use the JSP: UseBean in an instance. UploadBean upBean = new UploadBean (); MultipartFormDataRequest mrequest = null; Hashtable files = null; if (MultipartFormDataRequest.isMultipartFormData (request)) {mrequest = new MultipartFormDataRequest (request, null, 100 * 1024 * 1024, MultipartFormDataRequest.COSPARSER, "GBK" ); // Note that the encoding parameter String StT0 = MREQUEST.GETPARAMETER ("title"); "<BR> TITLE0 is:" stt0 "<br>"); string stt1 = new String ( Stt0.GetBytes ("ISO-8859-1"), "GBK"); Out.println ("<br> Title1 is:" stt1 "<br>"); // This is used to test whether the Title parameter is correct. When debugging, add a sentence if (true) return; Files = MREQUEST.GETFILES ();</p> <p>/ / Get the file name before modification string silverename = MREQUEST.GETPARAMETER ("OldFileName"); out.println ("SoldFileName:" soldfilename); string sWebrootPath = Request.getRealPath ("/"); // Get your web The root of the application. String spath = SWEBROOTPATH ​​ "attach"; int ifilecount = 0; string sserverfilename = ""; string slocalfilename = ""; // file gets IF ((files! = Null) | (! Files.isempty ())) {iFileCount = files.size (); UploadFile file = (UploadFile) files.get ( "attach"); sLocalFileName = file.getFileName (); out.println ( "sLocalFileName:" sLocalFileName); int ii = sLocalFileName.indexOf ( " "); // Take the suffix string sext = slocalfilename.substring (ii, slocalfilename.length ()); // Get no repetition name java.util.date dt = new java.util.date (System) .currentTimeMillis ()); SimpleDateFormat fmt = new SimpleDateFormat ( "yyyyMMddHHmmssSSS"); sServerFileName = fmt.format (dt); sServerFileName = sServerFileName sExt; // if the directory does not exist, a new File dir = new File (sPath ); If (! Dir.exists ()) {dir.mkdirs ();} UpBean.SetFolderstore (spath); // Set the directory UPBean.adduploadListener (filemover) you want to upload; // Add Filmover Monitor FileMover.setNewFileName (SserveFileName ); // Set file name upbean.store on the server (MREQUEST, "Attach"); // Upload Out.Println ("File Path IS" SPATH " SSERVERFILENA ME);</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-62556.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="62556" 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.057</b>, SQL: <b>10</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 = 'qGdSvxpB_2B5rR0r7GK6z25bOsmRA9IFpecf_2FSnV8lggtKfAavp_2B6vBaLNWLb4BtkK_2BgUtqcJzBOUTd7Lg9doHnQ_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>