eclipse html 文件编码格式错误导致乱码的分析及解决

1、使用STS(Spring 定制的eclipse)加载一个maven 项目。

2、设置项目的编码格式为UTF-8

eclipse html 文件编码格式错误导致乱码的分析及解决

3、问题出现了,java 代码都没有问题,发现html文件中文乱码。通过文件的属性查看,文件格式为GBK格式。(没有搞清楚为什么~~~)

4、通过设置文件的编码类型为UTF-8,中文可以正常显示。

eclipse html 文件编码格式错误导致乱码的分析及解决

5、但项目中有很多html文件,不能一个一个的单独设置,怎么办?

The General > Content Types preference page enables you to edit content types and their associated file names, editors and character sets. You can also associate arbitrary file names or file extensions with content types. A content type acts as a description of a certain class of files (for instance, XML files). Eclipse uses this description in various scenarios, such as editor look-ups and file comparisons.

To access the Content Types preference page, select Window > Preferences > General > Content Types.

eclipse html 文件编码格式错误导致乱码的分析及解决

设置后再次打开文件,发现所有的编码格式都变成UTF-8了。