美文网首页
Spring MVC处理请求参数中文乱码问题备注

Spring MVC处理请求参数中文乱码问题备注

作者: 爱吃兔子的萝卜 | 来源:发表于2017-04-01 11:36 被阅读0次

    一、针对POST请求

    在web.xml中配置:

      <filter>
        <filter-name>encodingFilter</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>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    

    二、针对GET请求:

    修改tomcat的server.xml配置文件:

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    

    改为:

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>
    

    三、针对AJAX的GET请求:

    修改tomcat的server.xml配置文件:

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    

    改为:

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
    

    相关文章

      网友评论

          本文标题:Spring MVC处理请求参数中文乱码问题备注

          本文链接:https://www.haomeiwen.com/subject/zvkiottx.html