前台传参到后台出现中文乱码问题

方法一:在web.xml文件中添加字符集过滤

	<filter>
        <filter-name>SpringEncodingFilter</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>SpringEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

方法二:

在server.xml中添加URIEncoding

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

方法三:在后台代码中转换格式

key为前台传过来的参数

String str = new String(key.getBytes(“iso-8859-1”),“UTF-8”);

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页