The problem of garbled characters in Java Web and the analysis of several ways of garbled characters in Chinese

Table of contents

0. There are various types of Chinese garbled characters and their causes

1. The Chinese content output in the Servlet displays garbled characters

 2. Garbled characters appear in the Chinese content output in JSP


0. There are various types of Chinese garbled characters and their causes

Distinguish between the flaws and the flaws? Most of them are in unfamiliar ancient Chinese with mixed Japanese and Korean Read UTF-8 encoded Chinese in GBK

����Ҫ�¨²�ѧϰ�

�����

Most characters are small squares Read GBK-encoded Chinese in UTF-8
由月è¦�好好å¦ä¹ 天天å�'上 Most of the characters are various symbols Read UTF-8 encoded Chinese in ISO8859-1 mode
ÓÉÔÂÒªººÃѧϰÌìÌìÏòÉÏ Most of the characters are letters with various diacritics above their heads Read GBK-encoded Chinese in ISO8859-1
From the month to study hard every day to?? Correct when the length of the string is even, and the last character becomes a question mark when the length is odd Read UTF-8 encoded Chinese in GBK mode, and then read it again in UTF-8 format
How to learn how to learn how to learn how to learn how to learn what to do All Chinese characters, and most of the characters are the characters of "Kun Jin Kao" Read GBK-encoded Chinese in UTF-8, and then read it again in GBK format

1. The Chinese content output in the Servlet displays garbled characters

 This problem occurs because the encoding of the response is not set servletResponse.setContentType("text/html;charset=UTF-8");

This means to tell the browser to give you an html text, and the encoding format is UTF-8 , because the browser defaults to UTF-8.

Another is that you set the encoding format of the response, but it is still garbled.

This is the problem of the inconsistent encoding format of the software you use to write.

 In the corresponding position in the settings, change all the encoding formats to UTF-8 (because my other encoding formats are UTF-8, for consistency, so I changed to UTF-8) to solve the problem

 The reason for the garbled characters is that when transcoding, the encoding formats on both sides are inconsistent.

 2. Garbled characters appear in the Chinese content output in JSP

People with Html foundation may think that the encoding format is not set under the <head> tag, resulting in garbled characters

But you will find that there are still garbled characters even after adding it, indicating that it has not been changed

 Since the object we use is JSP, we need to use jsp's own language to modify the encoding format

Guess you like

Origin blog.csdn.net/qq_64552181/article/details/129727243