一段java代码,用来生成html文件,向文件中写内容后,出现下列情形:
1)在main方法中本地运行application不乱码,tomcat运行时乱码。
肯定是编码造成的,本地的编码环境和tomcat的编码环境肯定不一样:
Properties initProp = new Properties(System.getProperties());
System.out.println("当前系统编码:" + initProp.getProperty("file.encoding"));
System.out.println("当前系统语言:" + initProp.getProperty("user.language"));
打印一下,果然,本地运行时编码 UTF-8 ,tomcat运行时编码GBK
解决方法:修改eclipse window preference-->general-->workspace: text file ecnoding,选择utf-8

网友评论