简体   繁体   中英

How to handle special characters in path variables

I am taking variable names from a path variable in my spring application.

However that fails in some cases when URL contains special characters

For eg http://www.loudletters.com/ll/rest/celebrityprofile/2S/Jan%20Min%C3%83%C2%A1%C3%85%C2%99 gives page not found error.

How to handle this?

I handle UTF-8 path variables just fine. What you need to do is:

  • set UTF-8 for URIs in your servlet container configuration
  • read the input as utf-8 (probably using spring's CharacterEncodingFilter )

The encoding and decoding should be done automatically by the servlet container and the browser.

您是否考虑过使用java.net.URLDecoderjava.net.URLEncoder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM