最近遇到的关于struts2.2.1中关于国际化编码乱码问题。
解决方法:
1、MyEclipse编码设置
我的Myeclipse6.5GA安装后编码默认是GBK,外面的人一般推荐用UTF-8。
全局编码设置:编码设置的方法:ToolBar-->Window-->Preferences-->General-->Workspace-->Text file encoding,设置合适的编码。
局部编码设置:在源码按右键-->General-->Editors-->Test Editors-->Spelling-->Encoding,这里是设置单个文件的编码。
2、在properties文件中添加国际化信息。
3、在jsp页面设置编码方式和Myeclipse设置的编码方式一致。一般为UTF-8。
4、在struts.xml中的配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"F:\install\struts2\struts2-core-2.2.1\struts-2.1.7.dtd">
<!-- struts是struts2配置文件的根元素 -->
<struts>
<constant name="struts.custom.i18n.resources" value="messageResource"></constant>
<constant name="struts.i18n.encoding" value="GBK"></constant>
...
</struts>
解决方法:
1、MyEclipse编码设置
我的Myeclipse6.5GA安装后编码默认是GBK,外面的人一般推荐用UTF-8。
全局编码设置:编码设置的方法:ToolBar-->Window-->Preferences-->General-->Workspace-->Text file encoding,设置合适的编码。
局部编码设置:在源码按右键-->General-->Editors-->Test Editors-->Spelling-->Encoding,这里是设置单个文件的编码。
2、在properties文件中添加国际化信息。
3、在jsp页面设置编码方式和Myeclipse设置的编码方式一致。一般为UTF-8。
4、在struts.xml中的配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"F:\install\struts2\struts2-core-2.2.1\struts-2.1.7.dtd">
<!-- struts是struts2配置文件的根元素 -->
<struts>
<constant name="struts.custom.i18n.resources" value="messageResource"></constant>
<constant name="struts.i18n.encoding" value="GBK"></constant>
...
</struts>