What's the difference between “URIEncoding” of Tomcat, Encoding Filter and request.setCharacterEncoding

前端 未结 2 1992
生来不讨喜
生来不讨喜 2021-02-09 21:46

There may be many ways to solve encoding problem:

  • Encoding filter like Spring MVC UTF-8 Encoding

  • Setting URIEncoding=UTF-8 in server.xml of Tom

相关标签:
2条回答
  • 2021-02-09 22:09

    for tomcat7

    • CharacterEncodingFilter configures encoding of request body. That is, it affects encoding of POST request parameters, etc, but doesn't affect encoding of GET parameters

    • useBodyEncodingForURI="true" tell tomcat to use CharacterEncoding( can be set by CharacterEncodingFilter) to parse QueryString. it's affect GET request parameter .

    • URIEncoding to parset URI , default is ISO-8859-1.

    for tomcat8

    • default UTF-8.
    0 讨论(0)
  • 2021-02-09 22:17
    • CharacterEncodingFilter configures encoding of request body. That is, it affects encoding of POST request parameters, etc, but doesn't affect encoding of GET parameters

    • URIEncoding is used to specify encoding of the URI, therefore it affects GET parameters

    • useBodyEncodingForURI="true" tells Tomcat to use encoding configured for request body when decoding URIs. So, as far as I understand, if you set CharacterEncodingFilter and useBodyEncodingForURI="true" then you don't need URIEncoding.

    In practice, you need to two things to solve possible problems with encoding of parameters:

    • CharacterEncodingFilter for POST requests

    • URIEncoding (or useBodyEncodingForURI="true") for GET requests

    0 讨论(0)
提交回复
热议问题