java - 如何处理url中的特殊字符作为参数值?

标签 java javascript html http spring-mvc

谁能建议如何处理下面的 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/

相关文章:

javascript - 如何加载两个javascript文件?

javascript - 如何将从数据库中提取的数字传递到 javascript 数据部分?

java - CentOS 6 中 JVM 的 CPU 使用率总是超过 100%

java - 如何选择将什么实现注入(inject)到 Autowiring 的构造函数中

javascript - (facebook) flow - 类型注解是如何工作的

javascript - 按钮 onclick 打开 WordPress 短代码

java - 打印出链表

专门用于 Windows 的 java 库

javascript - jQuery - 在按钮外部单击时保持对按钮的关注

javascript - 检查基于下拉问题的复选框