• 当发送 POST 请求时,带有中文的参数会发生乱码的情况
  • web.xml 当中添加一个 过滤器 即可解决

SpringMVC-解决POST请求中文参数乱码

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!-- 解决 POST 乱码问题 -->
    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <!-- 设置编码为 UTF-8 -->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

相关文章:

  • 2021-04-04
  • 2021-04-29
  • 2021-09-05
  • 2021-07-24
  • 2021-11-21
  • 2019-12-04
  • 2021-10-31
猜你喜欢
  • 2021-10-04
  • 2021-05-27
  • 2021-05-06
  • 2021-07-30
  • 2021-09-17
  • 2021-12-22
  • 2021-12-21
  • 2021-12-17
相关资源
相似解决方案