java - 配置springmvc字符過濾器,收到請求的中文依舊是亂碼該如何解決?
問題描述
<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>
用postman輸入中文參數調用,收到的都是亂碼,必須手動把參數從iso8859-1轉成utf-8
問題解答
回答1:試下 修改servlet容器的編碼設置 tomcat的話是server.xml,印象中
回答2:1.tomcat的server.xml配置
<Connector port='8080' protocol='HTTP/1.1' connectionTimeout='20000' redirectPort='8443' URIEncoding='UTF-8' useBodyEncodingForURI='true' />
2.繼承HttpServletRequestWrapper重寫getParameter方法,在這個方法里面做字符串的編碼轉換
