Struts2.0中的三种中文乱码转换方式
在开发中 都会遇到中文的编码转换的问题! 在Struts1中转换时用过滤器filter
但在Struts2.0中的方式就简单多 只要在文件中配置一下就好了!下面是三种方式
第一种 在Struts.xml中配置
<constant name="struts.i18n.encoding" value="GBK"/>
第二种 在 src中新建struts.properties
写入struts.i18n.encoding=GBK
第三种 在web.xml中配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>gbk</param-value>
</init-param>
</filter>
虽然 三种方式都可以配置 但是 优先级不同 从上到下一次变高!