浏览器到服务器(提交问题,原因:浏览器默认编码与服务器默认编码不一致导致)
post提交:通过web.xml配置过滤器
<!-- 解决post乱码问题 -->
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!-- 设置编码参是UTF8 -->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
get提交:在tomcat的/conf/server.xml搜索8080断口(8080是我的tomcat默认端口号)设置
<Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
服务器到浏览器(响应问题,原因:浏览器默认编码与服务器默认编码不一致导致)
request:会参考重定向的jsp指定的编码格式
response:在获取getWriter之前,response.setCharacterEncoding("utf-8");