src/share/classes/java/net/URL.java

Print this page




  63  * machine. If the port is not specified, the default port for
  64  * the protocol is used instead. For example, the default port for
  65  * {@code http} is {@code 80}. An alternative port could be
  66  * specified as:
  67  * <blockquote><pre>
  68  *     http://www.example.com:1080/docs/resource1.html
  69  * </pre></blockquote>
  70  * <p>
  71  * The syntax of {@code URL} is defined by  <a
  72  * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  73  * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  74  * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  75  * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  76  * also supports scope_ids. The syntax and usage of scope_ids is described
  77  * <a href="Inet6Address.html#scoped">here</a>.
  78  * <p>
  79  * A URL may have appended to it a "fragment", also known
  80  * as a "ref" or a "reference". The fragment is indicated by the sharp
  81  * sign character "#" followed by more characters. For example,
  82  * <blockquote><pre>
  83  *     http://java.sun.com/index.html#chapter1
  84  * </pre></blockquote>
  85  * <p>
  86  * This fragment is not technically part of the URL. Rather, it
  87  * indicates that after the specified resource is retrieved, the
  88  * application is specifically interested in that part of the
  89  * document that has the tag {@code chapter1} attached to it. The
  90  * meaning of a tag is resource specific.
  91  * <p>
  92  * An application can also specify a "relative URL",
  93  * which contains only enough information to reach the resource
  94  * relative to another URL. Relative URLs are frequently used within
  95  * HTML pages. For example, if the contents of the URL:
  96  * <blockquote><pre>
  97  *     http://java.sun.com/index.html
  98  * </pre></blockquote>
  99  * contained within it the relative URL:
 100  * <blockquote><pre>
 101  *     FAQ.html
 102  * </pre></blockquote>
 103  * it would be a shorthand for:
 104  * <blockquote><pre>
 105  *     http://java.sun.com/FAQ.html
 106  * </pre></blockquote>
 107  * <p>
 108  * The relative URL need not specify all the components of a URL. If
 109  * the protocol, host name, or port number is missing, the value is
 110  * inherited from the fully specified URL. The file component must be
 111  * specified. The optional fragment is not inherited.
 112  * <p>
 113  * The URL class does not itself encode or decode any URL components
 114  * according to the escaping mechanism defined in RFC2396. It is the
 115  * responsibility of the caller to encode any fields, which need to be
 116  * escaped prior to calling URL, and also to decode any escaped fields,
 117  * that are returned from URL. Furthermore, because URL has no knowledge
 118  * of URL escaping, it does not recognise equivalence between the encoded
 119  * or decoded form of the same URL. For example, the two URLs:<br>
 120  * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 121  * would be considered not equal to each other.
 122  * <p>
 123  * Note, the {@link java.net.URI} class does perform escaping of its
 124  * component fields in certain circumstances. The recommended way
 125  * to manage the encoding and decoding of URLs is to use {@link java.net.URI},




  63  * machine. If the port is not specified, the default port for
  64  * the protocol is used instead. For example, the default port for
  65  * {@code http} is {@code 80}. An alternative port could be
  66  * specified as:
  67  * <blockquote><pre>
  68  *     http://www.example.com:1080/docs/resource1.html
  69  * </pre></blockquote>
  70  * <p>
  71  * The syntax of {@code URL} is defined by  <a
  72  * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  73  * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  74  * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  75  * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  76  * also supports scope_ids. The syntax and usage of scope_ids is described
  77  * <a href="Inet6Address.html#scoped">here</a>.
  78  * <p>
  79  * A URL may have appended to it a "fragment", also known
  80  * as a "ref" or a "reference". The fragment is indicated by the sharp
  81  * sign character "#" followed by more characters. For example,
  82  * <blockquote><pre>
  83  *     http://www.oracle.com/technetwork/java/index.html#chapter1
  84  * </pre></blockquote>
  85  * <p>
  86  * This fragment is not technically part of the URL. Rather, it
  87  * indicates that after the specified resource is retrieved, the
  88  * application is specifically interested in that part of the
  89  * document that has the tag {@code chapter1} attached to it. The
  90  * meaning of a tag is resource specific.
  91  * <p>
  92  * An application can also specify a "relative URL",
  93  * which contains only enough information to reach the resource
  94  * relative to another URL. Relative URLs are frequently used within
  95  * HTML pages. For example, if the contents of the URL:
  96  * <blockquote><pre>
  97  *     http://www.oracle.com/technetwork/java/index.html
  98  * </pre></blockquote>
  99  * contained within it the relative URL:
 100  * <blockquote><pre>
 101  *     FAQ.html
 102  * </pre></blockquote>
 103  * it would be a shorthand for:
 104  * <blockquote><pre>
 105  *     http://www.oracle.com/technetwork/java/index.html
 106  * </pre></blockquote>
 107  * <p>
 108  * The relative URL need not specify all the components of a URL. If
 109  * the protocol, host name, or port number is missing, the value is
 110  * inherited from the fully specified URL. The file component must be
 111  * specified. The optional fragment is not inherited.
 112  * <p>
 113  * The URL class does not itself encode or decode any URL components
 114  * according to the escaping mechanism defined in RFC2396. It is the
 115  * responsibility of the caller to encode any fields, which need to be
 116  * escaped prior to calling URL, and also to decode any escaped fields,
 117  * that are returned from URL. Furthermore, because URL has no knowledge
 118  * of URL escaping, it does not recognise equivalence between the encoded
 119  * or decoded form of the same URL. For example, the two URLs:<br>
 120  * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 121  * would be considered not equal to each other.
 122  * <p>
 123  * Note, the {@link java.net.URI} class does perform escaping of its
 124  * component fields in certain circumstances. The recommended way
 125  * to manage the encoding and decoding of URLs is to use {@link java.net.URI},