springMVC解決中文亂碼問題

2021-07-27 01:35:09 字數 1053 閱讀 7215

1.post請求亂碼問題

在web.xml中加入:

<

filter

>

<

filter-name

>characterencodingfilter

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

>

filter

>

<

>

<

filter-name

>characterencodingfilter

filter-name

>

<

url-pattern

>/*

url-pattern

>

>

2.對於get請求中文引數出現亂碼解決方法有兩個:

修改tomcat配置檔案新增編碼與工程編碼一致,如下:

另外一種方法對引數進行重新編碼:

string username new

string(request.getparamter("username").getbytes("iso8859-1"),"utf-8")

iso8859-1是tomcat預設編碼,需要將tomcat編碼後的內容按utf-8編碼

SpringMVC解決中文亂碼

springmvc可以在web.xml中通過配置characterencodingfilter過濾器來解決post請求中的中文亂碼,同時我們也要保證jsp頁面也是utf 8標準。在tomcat8及以後會自動解決get請求的亂碼,如果不是8及以後我們也可以手動配置解決 1.post亂碼通過過濾器解決 ...

springmvc 解決中文亂碼 2

表單提交的方式是post,那麼如何來解決post提交的中文亂碼問題呢?我們可在web.xml檔案中加入乙個過濾器,如下 characterencodingfilter org.springframework.web.filter.characterencodingfilter encoding ut...

springmvc框架解決中文亂碼

在使用servlet開發時,我們使用request設定編碼格式,一般在過濾器中設定。也就是設定傳送的格式和每次接受的資料都設定編碼個是為utf 8.request.setcharacterencording utf 8 response.setcontenttype text html charse...