First, smartupload upload file garbled solution

xiaoxiao2021-03-06  41

First, smartupload upload file garbled solution

Nausea Index: Five Stars Edition: 80% (file name issues are not set)

Problem Description: Web applications developed under Windows, using Smartupload upload files, very simple, is a form file formData.jsp, a file getData.jsp, debugging, when debugging, WINDOWS and Linux systems Normally, when the system is installed to another server, there is a problem that the acquisition form 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 perform GetByte () transcoding, using ISO-8859-1 and GB312 / GBK "to transform, unregistered, and UTF-8, no;

Also in <% @ page contenttype = "text / html; charset = GB2312"> Coding replacement, no;

Modify Linux lang = zh_cn.gb2312, no;

Modify the charset of web.xml, no;

At this point I have almost all related to all related pages, and I found this question and smartupload. But there are very few people who are solved, and the solutions to the solution are also very unhappy, so they posted on 9CBS, and the result is no one to pay attention to it. Nothing is top. Going to the development of a group asking, everyone is busy, and there is no time to take care. Continue ourselves, the result obtained with System.GetProperty ("file.encoding") is ANSI_X3.4-1968, what code is this? Go on Google, all useless information, at this time, I can't help but feel cold. . . NND, the problem is somewhat serious. .

When I got off work, I didn't have a result. I have already felt, I don't want to work overtime, but spending for a long time, I haven't got this "small problem", I really have no face, so I assured my head to my head, tomorrow Solve.

Back in the house, tea does not think about it. Look at QQ, chat with 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's anti-compilation is not the same as others, it will change it.

Find 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);

Modify to string S11 = new string (m_binarray, m_startdata, (m_enddata - m_startdata) 1, charsetname);

After compiling, upload, restart and try again, and find out 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 the source code should be able to solve the problem, just not finished, the file name is needed. Interested can try)

At this time, I naturally thought of other upload packs, I found out that some people say that Javazoom is a good, and then say it, Demo is simple,

After the test, it was found that as long as the page GetData.jsp was transferred. The transcoding method can be a single parameter, or you can use a sentence: Request.setCharacterencoding ("GBK");

MultipartformDataRequest (Request, NULL, 100 * 1024 * 1024, MultipartFormDataRequest.cosparser, "GBK");

This UPLOADBEAN is very considerate, actually provides a ChineseUpload.jsp example, in fact, is different from two sentences. 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 and restart, everything is OK!

Later, several related BUGs of the system were found, and they were drums, 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:

Table page

SSSFormData.jsp

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> fbeysss UploadBean Sample </ 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 "enctype =" multipart / form-data "> <input name =" title "type =" text "value =" Chinese words "> <TD class =" bodystyle "> Annex </ 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 page</p> <p>sssgetdata.jsp</p> <p><! - / / ================================================================================================================================================== ============================== // File: UploadBean upload instance // function: solve Chinese garbled, complete the file upload, and Upload renamed provide solutions // author: fbysss //msn:jameslastchina@hotmail.com // ============================= ============================================= -> <% @ 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 = "javazoom.upload. *"%> <% @ Page import = "Uploadutilities.filemover"%> <head> <meta http-equiv = "content-type" content = "text / html; charSet = GB2312"> </ head> <% request.setcharacterencoding ("GBK") ; // Set the encoding format, do not need one by one. FileMover filemover = new filemover (); // You can also use the JSP: UseBean in an instance.</p> <p>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-61417.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="61417" 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.034</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 = 'sVuVnpa30AUS2uy1uQJVEh55V6HtihY4o4FOTJDJImdmdwYP0chobbybB3a57eE19GxvwImohlp2JOiR7u5D7Q_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>