Character encoding in query string, hebrew

后端 未结 1 1930
深忆病人
深忆病人 2020-12-21 02:20

I am trying to send a GET request with query string parameter in hebrew. When the controller gets the request, the parameter is in gibberish. i\'ve added \"org.springframewo

相关标签:
1条回答
  • 2020-12-21 02:32

    As it turns out HttpServletRequest#setCharacterEncoding(String) which CharacterEncodingFilter uses

    Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader(). Otherwise, it has no effect.

    Which is no good for you since you aren't getting the parameters from the body, but rather from the query string.

    If you are using Tomcat, however, you are in luck. Tomcat has a special Connector attribute which, when set (it's unset by default), will use that same character encoding for the query string.

    That attribute is useBodyEncodingForURI. If you open up your Tomcat servet.xml file, you will find an element like (without the attribute)

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

    Add the attribute and it will work as intended. Make sure you are setting it for the appropriate Connector, HTTP in this case.

    Other Servlet containers probably have some similar configuration.

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