1 POST请求中文参数出现乱码解决【web.xml配置filter】


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>

2 get请求中文参数出现乱码解决


    方案A   修改tomcat配置文件添加编码与工程编码一致


<Connector URIEncoding="UTF-8" useBodyEncodingForURI="true" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>


    方案B  


String bname = request.getParameter("bname"); 

bname = new String(bname .getBytes("iso8859-1"),"utf-8"); 

————————————————

原文链接:https://blog.csdn.net/qq_40969108/article/details/97832554


最后修改:2020 年 02 月 13 日
如果觉得我的文章对你有用,请随意赞赏