Search code examples
javaurl-encoding

what is url double escaping?


I am looking to double escape a url string in java. I don't know what is meant by double escaping a url. I also request some one to post sample java code that I can use to do this.

thank you.


Solution

  • How can I double escape a url string in java

    The simple answer is by escaping it, and then escaping it a second time.

    Assuming that "escaping" really means URL encoding, then:

    String input = ...
    String output = URLEncoder.encode(URLEncoder.encode(input, "UTF-8"), "UTF-8");
    

    However, the correct solution is probably more complicated than that ... depending on what you are going to do with the result. For instance, if you URL encode a complete URL string (once or twice), it is no longer a valid URL.

    If you took the time to explain the context, we'd be in a better position to give you a solution that might actually work for you.