If I put the http://localhost:9000/space test URL to the address bar of a web browser it calls the server with http://localhost:9000/space%20test.
http://localhost:9000/specÁÉÍtest will be also encoded to http://localhost:9000/spec%C3%81%C3%89%C3%8Dtest.
If put the encoded URLs to the address bar (i.e. http://localhost:9000/space%20test and http://localhost:9000/spec%C3%81%C3%89%C3%8Dtest) they remain the same (they won't be double-encoded).
Is there any Java API or library which does this encoding? The URLs comes from the user so I don't know if they are encoded or not.
(If there isn't would it be enough to search for % in the input string and encode if it's not found, or is there any special case where this would not work?)
Edit:
URLEncoder.encode("space%20test", "UTF-8") returns with space%2520test which is not what I would like since it is double-encoded.
Edit 2:
Furthermore, browsers handle partially encoded URLs, like http://localhost:9000/specÁÉ%C3%8Dtest, well, without double-encoding them. In this case the server receives the following URL: http://localhost:9000/spec%C3%81%C3%89%C3%8Dtest. It is same as the encoded form of ...specÁÉÍtest.
URLEncoder.encode()method? - Buhake Sindi