SpringMVC解決亂碼問題
- 在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
>
<
init-param
>
<
param-name
>
forceEncoding
</
param-name
>
<
param-value
>
true
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
characterEncodingFilter
</
filter-name
>
<
url-pattern
>
/
*</
url-pattern
>
</
filter-mapping
>
- 如果還不行,在SpringMVC.xml中配置以下!!!!!!
<
mvc
:annotation-driven
>
<
mvc
:message-converters
>
<
bean
class
="org.springframework.http.converter.StringHttpMessageConverter"
>
<
property
name
="supportedMediaTypes"
>
<
list
>
<!--<span style="white-space:pre"></span>-->
<
value
>
text/html;charset=UTF-8
</
value
>
<
value
>
application/json;charset=UTF-8
</
value
>
<
value
>
*/*;charset=UTF-8
</
value
>
</
list
>
</
property
>
</
bean
>
</
mvc
:message-converters
>
</
mvc
:annotation-driven
>