SpringMVC---控制器接收到的中文数据乱码

2021-05-03 19:28

阅读:560

标签:nec   字符集   gen   filter   port   cee   ram   编码格式   字符   

spring MVC中默认的编码格式为“ISO-8859-1”,页面一般数据格式设置为UTF-8,所以导致了乱码

method=POST时

在web.xml中配置Spring字符过滤器,添加:


    filter>
        filter-name>SpringEncodingFilterfilter-name>
        filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        init-param>
            param-name>encodingparam-name>
            param-value>UTF-8param-value>
        init-param>
        init-param>
            param-name>forceEncodingparam-name>
            param-value>trueparam-value>
        init-param>
    filter>
    filter-mapping>
        filter-name>SpringEncodingFilterfilter-name>
        url-pattern>/*url-pattern>
    filter-mapping>

method=GET时

在tomcat的server.xml添加URIEncoding=“utf-8”

Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
 
变更为:
Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8"/>

 

SpringMVC---控制器接收到的中文数据乱码

标签:nec   字符集   gen   filter   port   cee   ram   编码格式   字符   

原文地址:https://www.cnblogs.com/-217/p/13197312.html


评论


亲,登录后才可以留言!