Today, when making a Java Web project, the Chinese characters in HTML are displayed as garbled in the browser, and the possible reasons for this analysis are:
(1) There is a default encoding in the HTML file attribute, and if its settings conflict with the content CharSet property setting in the HTML document, it is displayed as garbled.
(2) related to the browser, if the HTML encoding method and the browser default encoding method, it will appear garbled.
Directly below, look at my experiment:
(1) The HTML file attributes and content charset are set to UTF-8, but the browser defaults to GBK encoding, which shows garbled characters. I used Google Chrome browser and Sogou browser have tried, the results are garbled.
HTML itself file property encoding settings: In MyEclipse, select the HTML file, right-click-->properties-->resource
The encoding format of the HTML file itself and the HTML document
The results show garbled characters:
(2) The HTML file itself chooses the default settings, the Content CharSet property is set to UTF-8, and the result is garbled
(3) The HTML itself file property is set to UTF-8, but the content charset is set to GBK, which conflicts and is displayed as garbled:
(4) The HTML itself is set to GBK, and the content charset in the document is also set to UTF-8, the results are displayed as normal
Normal results
Summary: If the Chinese in the HTML document is garbled in the browser, look for the reason in two ways: (1) HTML itself property encoding settings and content CharSet settings conflict (2) and browser encoding format is not compatible
A solution that displays garbled characters in HTML files in a Java Web project in a browser