How to handle Java garbled

Source: Internet
Author: User

Why is garbled is a topic that Chinese programmers can't avoid? This first to start from the coding mechanism, we are both Chinese and English encoding format is not the same, decoding is not the same!

If Chinese programmers do not encounter garbled characters, then only Chinese programming is used. I'm not sure how Chinese programming is going to work.

I write this is not to explain the gap between the Chinese and English, decoding, etc., I just combined with the garbled problem I encountered, and then did a solution garbled summary.

1, UTF8 to solve the problem of JSP Chinese garbled

Generally at the beginning of each page, add:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>

2. If the item is garbled:

Right click on the project name->properties->resource->text file encoding Click->other Select UTF-8

3, Tomcat 5.5 Chinese garbled

1) Just put the%tomcat installation directory

%/webapps\servlets-examples\web-inf\classes\filters\setcharacterencodingfilter.class file Copy to your WebApp directory/filters, If there is no filters directory,

Create a.

2) Add the following lines to your Web. xml:












</filter-mapping>

4, get the way to solve

Open the Tomcat Server.xml file, locate the chunk, and add the following line:

Uriencoding= "GBK"

The complete should be as follows:

<connector <br= "" >port= "maxthreads=" "minsparethreads=" 25 "


Disableuploadtimeout= "true" uriencoding= "GBK"/>

There is garbled in the 5.jar package

1) In the Eclipse menu bar, window–>preferences–>general–>content types will jar Content, Java Class File default Encoding are set to the code you want

2) Light setting above is not enough, but also need to set the workspace encoding. Window–>preferences–>general–>workspace, the default encoding for the text file encoding is also set to

And the same code as above.

3) Save, restart Eclipse to find the garbled problem solved.

The solution of 6.HTML5 Utf-8 Chinese garbled characters

HTML5 UTF-8 appear in the case of Chinese garbled, there should be a lot of friends have encountered it, with Notepad to write, save on the page run appeared garbled, replaced by GB2312 can correctly display Chinese,

The following is to discuss the specific solution

<! DOCTYPE html>
<meta charset= "UTF-8" >
<TITLE>HTML5 's title </title>
<body>
<P>HTML5 's content! Hello</p>
</body>

Write in Notepad, after saving on the webpage run garbled, replaced by GB2312 can display Chinese correctly

The code is fine, and the problem is with Notepad. <meta charste= "Utf-8" > just tells the browser to use Utf-8 to explain, and the document's encoding is determined at the time you save the selection,

If you save ANSI and then use Utf-8 to explain, must be garbled, Notepad, the default saved file format is ANSI, so when saving to be modified to uif-8.

7.js file display garbled in Chinese

JavaScript file Xx.js Edit save when there is an encoding scheme (such as GBK), when the file is opened when the encoding used (such as UTF-8) and save the encoding scheme is inconsistent, there will be garbled Chinese display.

Solution:

(1) When using the editor to open the browsing, the selection and the original file encoding (such as GBK) the same encoding method to view, there will be no garbled;
(2) Select the Xx.js in the package Explorer in Eclipse, select Properties in the right-click menu, and select the encoding (such as GBK) in the text file encoding with the xx.js edit when saving, it can be displayed normally;

8. The text snippet in JavaScript in the Web page is garbled

In Eclipse or editor xx.js Chinese display Normal, in the page call Xx.js, after the execution of the page results in the Text field display garbled.

Solution:

On the page referencing Xx.js, "show" plus the encoding of the Xx.js file to match the encoding of the Xx.js file itself (such as GBK).

<script type= "Text/javascript" language= "JavaScript" src= "/js/xx.js" charset= "GBK" ></script>

Suggestions:

(1) When you create a new xx.js with Eclipse or myeclipse, it is recommended that you change the text file encoding to UTF-8 and then edit save.
(2) Save xx.js with a text document or other editor, it is recommended to save it in UTF-8 encoding mode.
(3) on the page referencing Xx.js, "display" plus the encoding of the Xx.js file UTF-8.

<script type= "Text/javascript" language= "JavaScript" src= "/js/xx.js" charset= "Utf-8" ></script>

How to handle Java garbled

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.