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

前端 未结 2 1998
生来不讨喜
生来不讨喜 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: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

提交回复
热议问题