Encoding white spaces in url.

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 5.x
    • 4.x

Issue

  • How to encode white spaces in url?
  • Are spaces a valid charater in url?
  • White spaces in url are replaced with "+" character.

Resolution

  • Spaces are not a valid character in a URL, so while encoding, a whitespace is percent encoded (or replaced with a + for query parameters).
  • A solution could be manually replacing the '+' character.
  System.out.println(java.net.URLEncoder.encode("Hello World", "UTF-8").replace("+", " "));

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.