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

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");
主站蜘蛛池模板: 开阳县| 土默特右旗| 仙游县| 五常市| 新建县| 屏东市| 红桥区| 卓尼县| 衡南县| 靖宇县| 遵化市| 寿光市| 柏乡县| 米易县| 鸡西市| 慈利县| 青海省| 杭锦后旗| 双城市| 台北县| 景德镇市| 泸西县| 新巴尔虎左旗| 博湖县| 佛山市| 巫山县| 琼中| 高台县| 佳木斯市| 武宣县| 德江县| 花垣县| 博白县| 尚义县| 金坛市| 柘荣县| 卓资县| 临潭县| 江永县| 绥化市| 镇坪县|