< prev index next >

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

Print this page




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




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


< prev index next >