Home | | Internet Programming | Uniform Resource Locator (URL)

Chapter: Web or internet Programming : Basic Network and Web Concepts

Uniform Resource Locator (URL)

Uniform Resource Locator (URL) is a Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it.

URL

 

       Uniform Resource Locator (URL) is a Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it.

 

       The best-known example of a URL is the "address" of a web page on the World Wide Web, e.g. http://www.example.com

 

       Every URL consists of some of the following: the scheme name (commonly called protocol), followed by a colon, then, depending on scheme, a hostname (alternatively, IP address), a port number, the path of the resource to be fetched or the program to be run, then, for programs such as Common Gateway Interface (CGI) scripts, a query string, and with HTML documents, an anchor (optional) for where the page should start to be displayed.

 

       The combined syntax is

scheme://username:password@domain:port/path?query_string#anchor

 

 

       The scheme name, or resource type, defines its namespace, purpose, and the syntax of the remaining part of the URL. Most Web-enabled programs will try to dereference a URL according to the semantics of its scheme and a context. For example, a Web browser will usually dereference the URL http://example.org:80 by performing an HTTP request to the host example.org, at the port number 80. Dereferencing the URN mailto:bob@example.com will usually start an e-mail composer with the address bob@example.com in the To field.

 

       Other examples of scheme names include https:, gopher:, wais:, ftp:. URLs that specify https as a scheme (such as https://example.com/) denote a secure website.

 

       The registered domain name or IP address gives the destination location for the URL. The domain google.com, or its IP address 72.14.207.99, is the address of Google's website.

 

       The hostname and domain name portion of a URL are case-insensitive since the DNS is specified to ignore case. http://en.wikipedia.org/ and HTTP://EN.WIKIPEDIA.ORG/ both open the same page.

 

       The port number is optional; if omitted, the default for the scheme is used. For example, if http://myvncserver.no-ip.org:5800 is typed into the address bar of a browser it will connect to port 5800 of myvncserver.no-ip.org; this port is used by the VNC remote control program and would set up a remote control session. If the port number is omitted a browser will connect to port 80, the default HTTP port.

 

       The path is used to find the resource specified. It is case-sensitive, though it may be treated as case-insensitive by some servers, especially those based on Microsoft Windows. If the server is case sensitive and http://en.wikipedia.org/wiki/URL is correct, http://en.wikipedia.org/WIKI/URL/ or http://en.wikipedia.org/wiki/url/ will display an HTTP 404 error page.

 

 

       The query string contains data to be passed to web applications such as CGI programs. The query string contains name/value pairs separated by ampersands, with names and values in each pair being separated by equal signs, for example first_name=John&last_name=Doe.

 

       The anchor part when used with HTTP specifies a location on the page. For example http://en.wikipedia.org/wiki/URL#Syntax addresses the beginning of the Syntax section of the page.

 

       On some sites, the anchor may have other functions; see: fragment identifier.

 

Absolute URL

 

       It is the complete path including the domain - file name. Example: http://www.ip.com/images/logo.gif specifies an image file (logo.gif) located in the images directory, for the www.ip.com domain. This type of URL is what your must use when you want to link (or load) a file that is on another server.

 

       Another example is the absolute URL of this page (which is also the Address / Location of the file) = http://www.ip.com/help/path/index.php

 

Relative URL

       A relative URL points to a file/directory in relation to the present file/directory

 

       example on a web server (where the web root is public_html) Root (public_html)

.......index.html

 

.......top.gif

 

....images

......ibdhost.gif

 

....help

......path

........index.php (this page)

 

       For this page, the current page is the index.php file inside the path directory - inside the help directory. Therefore, the relative path to this page is

/help/path/index.php

       Then to load the ibdhost.gif image (top left of this page), the relative path to the image is

../../images/ibdhost.gif

 

Which means the ibdhost.gif image is in a directory two levels up from this index.php file - then down into the 'images' directory.

 

       The two dots .. instruct the server to move up one directory. Therefore two sets of ../../ moves up two levels to the root directory (public_html) - then opens the images directory and loads the ibdhost.gif file.

 

       if the image had been in the help directory the relative path would be ../help/imagename.jpg

 

Constructing a URL from its component parts

 

• To build a URL from three strings specifying the protocol, the hostname, and the file: public URL(String protocol, String hostname, String file) throws MalformedURLException

       This constructor sets the port to -1 so the default port for the protocol will be used. The file argument should begin with a slash, and include a path, a filename, and optionally a reference to a named anchor. Forgetting the initial slash is a common mistake, and one that is not easy to spot. Like all URL constructors, it can throw a MalformedURLException.

 

       Example

try {

URL u = new URL("http", "www.eff.org", "/blueribbon.html#intro");

 

}

 

catch (MalformedURLException e) { // All VMs should recognize http

}

 

       This creates a URL object that points to http://www.eff.org/blueribbon.html#intro, using the default port for the HTTP protocol (port 80). The file specification includes a reference to a named anchor. The code catches the exception that would be thrown if the virtual machine did not support the HTTP protocol. However, this shouldn't happen in practice.

 

       For those rare occasions when the default port isn't correct, the next constructor lets specify the port explicitly, as an int:

 

public URL(String protocol, String host, int port, String file) throws MalformedURLException • The other arguments are the same as for the URL(String protocol, String host,

String file) constructor and carry the same caveats.

 

Example 1:

try {

URL u = new URL("http", "lcsaxp.lcs.psu.edu", 1212, "/%3b&db=psu");

}

 

catch (MalformedURLException e) { System.err.println(e);

}

 

This code creates a URL object that points to http://lcsaxp.lcs.psu.edu:1212/%3b&db=psu,

 

Example 2:

The Parts of a URL

 

import java.net.*;

public class URLSplitter {

 

public static void main(String args[]) { for (int i = 0; i < args.length; i++) {

 

try {

 

URL u = new URL(args[i]);

System.out.println("The URL is " + u);

 

System.out.println("The scheme is " + u.getProtocol( ));

System.out.println("The user info is " + u.getUserInfo( ));

String host = u.getHost( );

 

if (host != null) {

 

int atSign = host.indexOf('@'); if (atSign != -1)

 

host = host.substring(atSign+1); System.out.println("The host is " + host);

}

 

else {

System.out.println("The host is null.");

 

}

 

System.out.println("The port is " + u.getPort( ));

System.out.println("The path is " + u.getPath( ));

System.out.println("The ref is " + u.getRef( ));

System.out.println("The query string is " + u.getQuery( ));

 

} // end try

 

catch (MalformedURLException e) { System.err.println(args[i] + " is not a URL I understand.");

 

}

System.out.println( );

 

} // end for

} // end main

} // end URLSplitter

 

% java URLSplitter \ http://www.ncsa.uiuc.edu/demoweb/html-primer.html#A1.3.3.3 \ ftp://mp3:mp3@138.247.121.61:21000/c%3a/ \ http://www.oreilly.com \ http://metalab.unc.edu/nywc/compositions.phtml?category=Piano \ http://admin@www.blackstar.com:8080/ \

 

The URL is http://www.ncsa.uiuc.edu/demoweb/html-primer.html#A1.3.3.3 The scheme is http

The user info is null

 

The host is www.ncsa.uiuc.edu

The port is -1

 

The path is /demoweb/html-primer.html The ref is A1.3.3.3

The query string is null


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Web or internet Programming : Basic Network and Web Concepts : Uniform Resource Locator (URL) |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.