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

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");
主站蜘蛛池模板: 靖西县| 马山县| 江孜县| 贵定县| 贞丰县| 同江市| 江阴市| 宜阳县| 新昌县| 黄大仙区| 淳安县| 大同市| 红河县| 枞阳县| 大名县| 蓬溪县| 南昌市| 衡水市| 沁阳市| 六枝特区| 密山市| 白朗县| 鄂温| 长垣县| 兴山县| 三门县| 百色市| 巍山| 德昌县| 永清县| 乐亭县| 三河市| 红桥区| 法库县| 土默特左旗| 青川县| 惠来县| 九龙坡区| 噶尔县| 舞阳县| 仁寿县|