About SmartUpload The Chinese garbled problem of the toolkit , The output is garbled in Chinese on the server , And English numbers , No problem , I read other people's questions and answers on the Internet , It makes sense to me , But you don't have to , Finally, in many experiments , Finally I found the problem . Next, let's talk about my Chinese garbled problem .

First look at it. jsp Page coding and mixed form data

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="/MvcPro/">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title> test </title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<form action="emp/add" method="POST" enctype="multipart/form-data">
<fieldset>
<legend> Please register </legend>
user name :<input type="text" name="username" value=" Li Si "><br><br>
pay &nbsp;&nbsp;&nbsp; information :<input type="text" name="sal" value="5000"><br><br>
job &nbsp;&nbsp;&nbsp; position :<input type="text" name="job" value=" contractor "><br><br>
Commission &nbsp;&nbsp;&nbsp; gold :<input type="text" name="comm" value="900"><br><br>
Department number :<input type="text" name="deptno" value="50"><br><br>
mirror &nbsp;&nbsp;&nbsp; slice :<input type="file" name="pic"><br><br>
<input type="submit" value=" Submit ">
<input type="reset" value=" Reset ">
</fieldset>
</form>
</body>
</html>

Here we see jsp Page coding uses UTF-8

And then look at it Servlet The original output part of the code

 //SmartUpload Instantiate in the abstract parent class .
super.saveFile(req, resp);
// adopt SmartUpload Instantiate the object smart Extract request, After getting the corresponding data .
String name =super.smart.getRequest().getParameter("username");
String sal = super.smart.getRequest().getParameter("sal");
String comm = super.smart.getRequest().getParameter("comm");
String job = super.smart.getRequest().getParameter("job");
System.out.println(comm);
// Output
System.out.println(" name :"+name+", Position :"+job);

The result is

In fact, the problem here is very simple , I set it myself request The coding filter , And then used request.setCharacterEncoding("utf-8"); It's no use .

Attention, everyone , The encoding here is HttpServletRequest Class encoding , And this way enctype="multipart/form-data" Use , The data we transmit to the server is not used HttpServletRequest, So coding doesn't work .

And through SmartUpload.getrequest() The object of acquisition is request Object is not HttpServletRequest Class object . So from request The string obtained in is not processed at all UTF-8 transcoding . Direct output will be garbled .

And then I use the string construction method new String(byte byte[],Character) Transcoding tests were carried out :

As a result, there is no garbled Chinese , So the final reason is JSP Page code UTF-8 code --》Tomcat The default transcoding to other formats --》 The server will do it again UTF-8 We didn't transcode the last step in the road .

SmartUpload Toolkit Chinese garbled problem detailed explanation of more related articles

  1. MySQL To solve the problem of garbled code

    When writing a project today , Inserting data manually in the database will not produce Chinese garbled code , But by javaWeb But there's a mess , After solving the garbled problem in the submitted form and response , It's still a mess . So I must be mine mysql There is a garbled code in the database .

  2. Chinese garbled URLEncode after , Background access is still garbled

    java When you get the parameters in , The default is iso8859-1 To decode , Then use it again URLEncode Of encoe Method to encode it once , The encoding format uses iso8859-1, So we get the initial use of utf ...

  3. SmartUpload Control Solutions to the problem of Chinese garbled code

    ( Random code is generally not unified , But when we use plug-ins , Let's go to the page , backstage , And transcoding between plug-ins is not necessarily uniform , This leads to the problem of garbled code ) First ,SmartUpload The use of Internet is very much , I'm not going to repeat it here , The main solution is to solve the problem of "why is it chaotic" ...

  4. PHPExcel Detailed explanation of Chinese user manual

    /** * * execl Export data * Application scenarios : Order export * @param string $title The model name ( Such as Member), Prefix used to export generated file names * @param array $cellN ...

  5. java code , Detailed explanation of garbled code problem

    One . Common encoding formats 1.ASCII Basic coding , English and Western European characters . Use a byte of low 7 Who said , altogether 128 individual . 0~13 Is a control character such as newline . enter . Delete etc. ,32~126 Is print character , Keyboard entry . 2.IOS-8859 ...

  6. hanlp Source code analysis of the Chinese word segmentation algorithm

    Words and pictures Word graph refers to the graph of all the words in a sentence . If a word A The next word in English might be B Words , that A and B There is a path between E(A,B). A word can have more than one follow-up , There may also be multiple precursors , The picture they make is what I call the word picture . Need to be sparse 2 dimension ...

  7. PHPExcel Detailed explanation of Chinese user manual Two

    $objPHPExcel = new \PHPExcel(); // Define configuration $topNumber = 2;// There are several lines in the header $xlsTitle = iconv('utf-8', 'gb2312', ...

  8. linux Chinese garbled problem and locale Detailed explanation

    One . Modify the default language of the system and the Chinese garbled problem record. The default language of the system is /etc/sysconfig/i18n, If the Chinese system is installed by default ,i18n Is as follows : LANG="zh_CN.UTF-8&q ...

  9. JpGraph Use detailed Chinese garbled solution

    In front of JpGraph Use to explain this article , Have been to JpGraph This paper gives a detailed account of how to use , What I said is OK , Next, solve the Chinese garbled . JpGraph Why Chinese garbled stay JpGraph The default is to convert the string to utf ...

Random recommendation

  1. How to locate dead cycle or high CPU Usage rate (linux)

    How to locate dead cycle or high CPU Usage rate (linux)   Sure is CPU Too high Use top Observe if there is CPU The phenomenon of over utilization Find the thread Yes CPU All threads of a process that is overused are sorted ps H -e -o pid,tid ...

  2. EF MYSQL Cannot select Entity Framework version

    web.config Add the following configuration to the file , Then compile <provider invariantName="MySql.Data.MySqlClient" type="My ...

  3. be based on MATLAB The membership of cloud model is calculated

    ” cloud ” perhaps ’ Cloud drop ‘ It's the basic unit of the cloud model , A cloud is a distribution in its universe , It can be in the form of joint probability (x, u) To express The cloud model uses three data to represent its characteristics   expect : The expectation of the spatial distribution of cloud droplets in the universe , Generally, the symbol is used Εx Express .  entropy : No ...

  4. VB Get browser version

    String userAgent; userAgent = Request.UserAgent; ) { // The browser is Microsoft Internet Explorer V ...

  5. c - Convert decimal to string .

    Recursive implementation : /* Input : Decimal integer . Output : character string . */ void conv(int decimal) { != ) conv(); putchar( + '); }

  6. java Basics ( Three chapters )

    java Basics ( Three chapters ) One . basic if structure 1. flow chart l  Input and output l  Judgment and branching l  Flow line 1.1              ordinary if conditional if( expression ){            // surface ...

  7. Spring Framework series of transaction management

    1. Business Review (1). What is business : A transaction is a logical set of operations , The logical units that make up this set of operations , Or make it together , Or fail together . (2). Transaction features (ACID) Atomicity : Emphasize the indivisibility of transactions Uniformity : The execution of a transaction ...

  8. [HNOI2009] The smallest circle ( Fractional programming +SPFA Negative link )

    Answer key : Find the minimum value of the ratio of ring length to the number of ring edges , The o min{Σw[i]/|S|}, among i∈S. There are two parts to this question at a glance , Then you can convert the number of edges , Suppose there is Σw[i]/|S|<=k, be Σw[i]-k|S|<=0, namely Σ ...

  9. WinHex Data recovery notes ( One )

    WinHex Data recovery is powerful , It can scan and recover data from sectors on the hardware cluster . First of all, winhex Each function of . Then record a Word Restore after deleting the document . 1.WinHex Data recovery software editing area input and other common text ...

  10. SQL Performance analysis

    SELECT s2.dbid, s1.sql_handle, (SELECT TOP SUBSTRING(s2.text,statement_start_offset / + , ( (CASE WH ...