當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
总结:SpringMVC 中 GET 和 POST 方式请求中的中文乱码问题
生活随笔
收集整理的這篇文章主要介紹了
总结:SpringMVC 中 GET 和 POST 方式请求中的中文乱码问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
以下是 SpringMVC 中 GET 和 POST 方式請求中的中文亂碼問題的解決方法。
1,GET?方式中文亂碼:
修改tomcat的server.xml配置文件,如下:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/> 改為: <Connector connectionTimeout="20000" port="8082" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
加上 useBodyEncodingForURI="true" 后,可以解決普通get請求的中文亂碼問題,但是對于通過ajax發起的get請求中文依然會亂碼,請把 useBodyEncodingForURI="true" 改為 URIEncoding="UTF-8" 即可。
我自己試了一下,只要加上?URIEncoding="UTF-8" 對所有類型的 GET 請求都起作用。
注意:如果你是更改的tomcat安裝目錄的server.xml配置文件,那么在用eclipse運行項目時會發現配置沒起作用,其實是因為eclipse在運行項目時是用的eclipse中配置的tomcat,那么問題就好解決了,打開eclipse中的tomcat配置文件,改為如下即可:
2,POST?方式中文亂碼:
在項目中的 web.xml 中加上如下配置即可:
<!-- Spring EncodingFilter --><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> ------------------------------------------------
相關參考:
http://www.cnblogs.com/liukemng/p/4178882.html
http://linvar.iteye.com/blog/1662232
轉載于:https://my.oschina.net/bbsyuemoncn/blog/516191
總結
以上是生活随笔為你收集整理的总结:SpringMVC 中 GET 和 POST 方式请求中的中文乱码问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpriteBuilder中不能编辑自定
- 下一篇: Adapter