A solution that displays garbled characters in HTML files in a Java Web project in a browser

Source: Internet
Author: User

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

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.