What is the best way to encode URL strings such that they are rfc2396 compliant and to decode a rfc2396 compliant string such that for example %20 is replaced with a space c
The javadocs recommend using the java.net.URI class to accomplish the encoding. To ensure that the URI class properly encodes the url, one of the multi-argument constructors must be used. These constructors will perform the required encoding, but require you to parse any url string into the parameters.
If you want to decode, you must construct the URI with the single argument constructor, which does not do any encoding. You can then call methods such as getPath() etc. to retrieve and build the decoded URL.