SSM-SpringMVC-19:SpringMVC中请求和响应的乱码解决

 

 

 ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

 

配置一道拦截器即可解决乱码

配置方式如下:

 

在web.xml中:

 

  <!--过滤器处理乱码-->
  <filter>
    <filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

 

posted @ 2018-03-27 20:21  晨曦Dawn  阅读(237)  评论(0编辑  收藏  举报