A solution for displaying garbled characters in HTML files in a Java Web project in a browser

Source: Internet
Author: User

A solution for displaying garbled characters in HTML files in a Java Web project in a browser

When I was working on a Java Web project today, Chinese characters in html are garbled in the browser. The possible causes are as follows:

(1) There is a default encoding method in html file attributes. If its settings conflict with the content charset attribute settings in html documents, garbled characters are displayed.

(2) It is related to the browser. If the html encoding method is different from the default encoding method of the browser, garbled characters will appear.

View my experiment directly below:

(1) html file properties and content charset are set to UTF-8, but the default browser is GBK encoding, display garbled. I tried both Google Chrome and sogou, and the results were garbled.

Encoding of html file attributes: In MyEclipse, right-click the html file and choose Properties> Resource

The encoding format of the html file and the content charset attribute settings in the html document


The result is garbled:


(2) The default settings of the html file, content charset attribute is set to UTF-8, the results also show garbled


(3) html file properties are set to UTF-8, but content charset is set to GBK, the two conflict, the display is garbled:


(4) The html property is set to GBK, the content charset in the document is also set to UTF-8, The results show normal


Normal Results


Conclusion: If Chinese characters in the html document are garbled in the browser, find the cause from two aspects: (1) Conflict between the attribute encoding settings of html and the content charset settings (2) incompatible with the browser encoding format

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.