总结两个 方法
js里面 两次编码
retStr = encodeURI(encodeURI(retStr));
controller 解码
今天测试spring mvc ,中文乱码,在web.xml中加上
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
过滤所有请求,但还是有问题,最后发现是表单的问题,在表单中method默认是get,而以上过滤器只对post有效果,如果是get,需要修改 Tomcat根式目录的 conf/server.xml文件中,找<Connector port="8080" />,在里面加 <Connector port="8080" uRIEncoding="utf-8" />
js里面 两次编码
retStr = encodeURI(encodeURI(retStr));
controller 解码
今天测试spring mvc ,中文乱码,在web.xml中加上
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
过滤所有请求,但还是有问题,最后发现是表单的问题,在表单中method默认是get,而以上过滤器只对post有效果,如果是get,需要修改 Tomcat根式目录的 conf/server.xml文件中,找<Connector port="8080" />,在里面加 <Connector port="8080" uRIEncoding="utf-8" />