官术网_书友最值得收藏!

URLs, URLConnections, and the ContentHandler classes

While surfing the internet, we use URLs extensively. As a result, many of us perceive URL as the names of files located on the WWW, but that is not true; a URL could also point to other resources on a network, such as a database query or command output and so on.

A URL can be defined as an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the internet.

Every URL has two main components: a protocol identifier and resource name. Suppose we have http://www.google.com; in this case, HTTP is the protocol identifier and www.google.com is the resource name. They are joined together with a colon (:) followed by two slashes (//), as shown in the following screenshot:

Protocols could be of many types, such as HTTP, HTTPS, file, gopher, FTP, and news. Here, the resource name represents the full address of the resource and contains the hostname, filename, port number, and reference. In many URLs, you might have seen that the hostname is mandatory, whereas the filename, port number, and reference are optional.

URL can be constructed in Java using the following syntax; note that URL addresses are passed in the form of a string to the URL class constructor:

URL urlHandle = new URL("http://example.com/");

The URL shown in the preceding code is the absolute URL where all the details are given. In addition to this, URLs could be relative to some already existing URL, as shown in the following example:

URL urlHandle = new URL("http://example.com/pages/");
URL firstPage = new URL(urlHandle, "page1.html");
主站蜘蛛池模板: 逊克县| 廊坊市| 宁远县| 桃园市| 壶关县| 富锦市| 博客| 张家川| 峨边| 陆河县| 璧山县| 翁源县| 伊金霍洛旗| 余姚市| 石屏县| 梧州市| 平度市| 错那县| 铅山县| 平定县| 沙坪坝区| 鹤岗市| 洛阳市| 迭部县| 称多县| 安吉县| 宁陕县| 台北县| 花莲市| 松原市| 东安县| 通江县| 石河子市| 扎赉特旗| 荥阳市| 綦江县| 余庆县| 贞丰县| 克拉玛依市| 丹巴县| 衡东县|