解决中文乱码的问题
我之前做的例子中输入了中文的用户名,在后端显示的就是乱码,这是因为struts2默认采用的编码是UTF8,我们可以通过设置struts.i18n.encoding属性来改变
struts2的默认编码。修改src目录下的struts.xml文件,使用constant元素来配置struts.i18n.encoding属性,值为GBK或GB2312
<struts>
<constant name="struts.i18n.encoding" value="GBK"/>
<package.....>
.......
</package>
</struts>
你也可以在struts.properties文件中设置struts.i18n.encoding属性。在str目录下新建struts.properties文件,内容如下:
struts.i18n.encoding=GBK
重启tomcat 就可以看到你是正常的了
posted on 2011-11-16 09:21 天马星空不脱离轨迹的猫 阅读(461) 评论(0) 编辑 收藏 举报