Spring/Rest @PathVariable character encoding

前端 未结 4 940
生来不讨喜
生来不讨喜 2020-12-01 08:11

In the environment I\'m using (Tomcat 6), percent sequences in path segments apparently are decoded using ISO-8859-1 when being mapped to a @PathVariable.

I\'d like

4条回答
  •  佛祖请我去吃肉
    2020-12-01 08:18

    The path variable is still decoded in ISO-8859-1 for me, even with the Character Encoding Filter. Here is what I had to do to get around this. Please let me know if you have any other ideas!

    To see the actual UTF-8 decoded characters on the server, you can just do this and take a look at the value (you need to add "HttpServletRequest httpServletRequest" to your controller parameters):

    String requestURI = httpServletRequest.getRequestURI();
    String decodedURI = URLDecoder.decode(requestURI, "UTF-8");
    

    I can then do whatever I want (like get the parameter manually from the decoded URI), now that I have the right decoded data on the server.

提交回复
热议问题