谁能建议如何处理下面的 url,因为 strLocation 的参数值具有特殊字符?提前致谢
http://localhost:8080/safp/contacts/FirmAddress.do?btnAction=FirmAddress&firmId=122379069&strLocation=!@#$%^&*()_+&async=true&newAccID=112
最佳答案
使用URLEncoder使用特殊字符对您的 URL 字符串进行编码。对字符串进行编码时,适用以下规则:
- The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
- The special characters ".", "-", "*", and "_" remain the same.
- The space character " " is converted into a plus sign "+".
- All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented
by the 3-character string "%xy", where xy is the two-digit
hexadecimal representation of the byte. The recommended encoding
scheme to use is UTF-8. However, for compatibility reasons, if an
encoding is not specified, then the default encoding of the platform
is used.
例如,使用 UTF-8 作为编码方案,字符串 The string ü@foo-bar
将被转换为 The+string+%C3%BC%40foo-bar
因为在 UTF-8 中,字符 ü 被编码为两个字节 C3(十六进制)和 BC(十六进制),而字符 @ 被编码为一个字节 40(十六进制)。
关于java - 如何处理url中的特殊字符作为参数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19515616/