struts2乱码问题解决思路
乱码问题整改:
数据流过程(经历了几个编码和解码)。
数据库 ---> 服务端 ---> 页面
要注意的地方:
1、数据库到服务端:

2、服务端到页面
1)在struts.properties 中添加
struts.i18n.encoding=相关编码集
2)在struts.xml 中设定
<constant name="struts.i18n.encoding" value="utf-8"></constant>
3)在filter中 web.xml(项目的webxml中)
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
4)在struts.xml中的做以下配置:
<action name="getPowerListByUserId" class="com.boe.meeting.struts.login.LoginAction" method="getPowerListByUserId">
<result name="powerList" type="stream">
<param name="contentType">application/octet-stream;charset=utf-8</param>
<param name="powerList">inputStream</param>
</result>
</action>
5)在XxxxAction中设置参数:
Strign contentType="utf-8";
public String getContentType(){
}
public void setContentType(String contentType){
}
6) 保证action方法中的数据字符集(字符串、流)与以上的配置的编码格式相同。
注:
从5)到1)过程每一个配置都会覆盖上面的配置。

浙公网安备 33010602011771号