public class URLEncoder
extends java.lang.Object
For example, the following HTML URL string is not valid and would need to be encoded:
http://mySystem.myCompany.com/servlet/myServlet?parm1="/library/test1#partA"&parm2="/library/test2#partB"
The following example uses the URLEncoder class to encode two URL string parameter values:
HTMLForm form = new HTMLForm();
String action = "http://mySystem.myCompany.com/servlet/myServlet";
String parm1 = "parm1=" + URLEncoder.encode("\"/library/test1#partA\"");
String parm2 = "parm2=" + URLEncoder.encode("\"/library/test2#partB\"");
form.setURL(action + "?" + parm1 + "&" + parm2);
The delimiters that are encoded include:
| Constructor and Description |
|---|
URLEncoder() |
public static java.lang.String encode(java.lang.String url)
url - The URL to be encoded.public static java.lang.String encode(java.lang.String url,
boolean encodePath)
url - The URL to be encoded.encodePath - true if the "/" is encoded in the url; false otherwise. The default is true.