SpringMVC使用CharacterEncodingFilter解决中文乱码

SpringMVC使用CharacterEncodingFilter解决中文乱码

SpringMVC处理web请求时,当web请求的方式为post,会出现中文乱码。这时在web.xml文件使用CharacterEncodingFilter过滤器解决问题,代码如下:

 <filter>
 <filter-name>characterEncodingFilterfilter-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>forceRequestEncodingparam-name>
        <param-value>trueparam-value>
    init-param>
    
    <init-param>
        <param-name>forceResponseEncodingparam-name>
        <param-value>trueparam-value>
    init-param>
filter>
<filter-mapping>
    <filter-name>characterEncodingFilterfilter-name>
    
    <url-pattern>/*url-pattern>
filter-mapping>

你可能感兴趣的:(SpringMVC使用CharacterEncodingFilter解决中文乱码)