what does this method static encode() of the class URLEncoder do ? what is this translation of a string into x-www-form-urlencoded ?? in one of the examples its usage is like this: String ss = URLEncoder.encode(args);// the user enters some string at command line pw.println("string is : "+ss);//where pw is PrintWriter object here is the api encode(String s) Translates a string into x-www-form-urlencoded format.
It is meant for URL encoding the string. When URLs contain a query string, (name=value pairs), the values are encoded using this method. URL encoding includes converting spaces to + or %20 and all other non alpha-numeric characters are converted to their HEX value, which is of the form - %XX, where XX is the HEX value. So my name Manish Hatwalne becomes either Manish+Hatwalne or Manish%20Hatwalne. This can also safely pass values such as /, // and . (period) which have special meaning in the URL. Of course, there's a corresponding decode method for this. I believe this information is documented in the API as well. HTH, - Manish
Originally posted by Ed Bicker: Yes, but why do you need to URLEncode a string, in the first place. What good does it serve?
You would normally not need them because browser does this encoding when it issues a GET request. But in case you are using applets and issuing the GET request programmatically, then you would have to encode() them before it reaches the server.
Sab<br /> <br />Perfection does not come from belief or faith. Talk does not count for anything. Parrots can do that. Perfection comes through selfless work.<br />Swami Vivekananda