com.ibm.as400.util.html

Class URLEncoder

  • java.lang.Object
    • com.ibm.as400.util.html.URLEncoder


  • public class URLEncoder
    extends java.lang.Object
    The URLEncoder class encodes a string's delimiters for use in an HTML URL string.

    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:

    • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.
    • The space character ' ' is converted into a plus sign '+'.
    • All other characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.
    • Constructor Summary

      Constructors 
      Constructor and Description
      URLEncoder() 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      static java.lang.String encode(java.lang.String url)
      Encodes the URL.
      static java.lang.String encode(java.lang.String url, boolean encodePath)
      Encodes the URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URLEncoder

        public URLEncoder()
    • Method Detail

      • encode

        public static java.lang.String encode(java.lang.String url)
        Encodes the URL.
        Parameters:
        url - The URL to be encoded.
        Returns:
        The encoded string.
      • encode

        public static java.lang.String encode(java.lang.String url,
                              boolean encodePath)
        Encodes the URL.
        Parameters:
        url - The URL to be encoded.
        encodePath - true if the "/" is encoded in the url; false otherwise. The default is true.
        Returns:
        The encoded string.