Internet and Web Technology
Internet and Web Technology
Internet and Web Technology
UNIT STRUCTURE
1.0 Objective
1.1 Concept of Internet
1.2 Evolution of internet
1.3 Basic concepts
1.4 Communication on the Internet
1.5 Internet Domains
1.6 Internet Server Identities
1.7 Establishing Connectivity on Internet
1.8 Client IP Address
1.9 TCP/IP and its Services
1.10 Web Server
1.11 Web Client
1.12 Domain Registration
1.13 Summary
1.14 Question for Exercise
1.15 Suggested Readings
1.0 Objective
Defense Advanced Research Project Agency (DARPA) of US initiated a research activity that
eventually developed as a system for global data commmunication service known as the Internet.
The internet, today, is being operated as a joint effort of many different organizations. In this
unit, you will learn the basic concepts related to internet as well as the various mechanisms and
technologies involved in the deployment of the internet. Upon completion of this unit, the
readers shall be aware of the basic terms and terminologies, involved devices and mechnaisms
and the applications of the Internet.
Though the terms Internet and World Wide Web are used interchangeably in lay man terms they
are not the same. It is common practice to say "going on the Internet" whenever we open any
web page on a browser. However, the World Wide Web or the Web is one of the most popular
Internet services available. The Web is a collection of interconnected documents (web pages)
and other web resources, linked by hyperlinks and URLs. It uses HTTP as an underlying
protocol for information transfer which is one of the several other protocols available in
networking theory.
The Internet is a global collection of computer networks that are linked together by devices
called routers and use a common set of protocols for data transmission known as TCP/IP
(transmission control protocol / Internet protocol). The primary purpose of the Internet is to
facilitate the sharing of information. There are many different tools used on the Internet to make
this possible. Some of the more common tools include email, list servers, newsgroups, telnet,
gopher, FTP, and the World Wide Web. Probably the most popular of all Internet tools is the
World Wide Web.
WWW stands for World Wide Web. A technical definition of the World Wide Web is − All the
resources and users on the Internet that are using the Hypertext Transfer Protocol HTTP. The
World Wide Web is the universe of network-accessible information, an embodiment of human
knowledge. The World Wide Web is a way of exchanging information between computers on the
Internet, tying them together into a vast collection of interactive multimedia resources. It is a
hypertext interface to internet information resources.
Internet and Web is not the same thing: Web uses internet to pass over the information.
1.3.3.1 HTTP
HTTP is the short form for Hypertext Transfer Protocol. An example of the standard URL is
http://www.google.com. The prefix http in the URL designates the protocol being used for
communication. The HTTP protocol is used to access hypertext documents on the World Wide
Web.
1.3.3.2 URL
URL refers to Uniform Resource Locator. URLs are used as the address of the documents
available on the World Wide Web. A URL is the fundamental identifier of any resource available
on the web e. g., hypertext pages, images, and sound files. The standard format of a URL has
been specified as –
protocol://hostname/other_information
A protocol is, basically, a specification of the flow of information in a network. The protocol
required for accessing the resources available on the web is called Hyper Text Transfer Protocol
(HTTP). Other protocols supported by the web browsers include telnet, FTP, Gopher, etc. The
name of the protocol is followed by a colon, two forward slashes, and then the hostname. The
hostname refers to the computer having the requested resource. Hostname is followed by a single
forward slash and links to subdirectories or any particular file. The path to the directory holding
the requested file or resource may contain single forward slashes.
1.3.3.3 Website
Website refers to a collection of web pages usually written in markup language. For example:
www.google.com refers to the website of Google having ‘com’ as the domain name. Websites
can be understood as a location on the World Wide Web that holds the resources which people
can request when required. The first or the initial page of any website is known as the home page
of that particular website.
Websites are usually hosted on a computer which is known as a Web server. These servers
should require constant connectivity with the internet so that the resources stored by them can be
accessed from anywhere in the world. A web server is provided with a unique address which is
required to access the contents of the server. The unique address is the identifier for the server
and is termed as IP Address. These IP Addresses comprise of a series of four numbers separated
by dots or periods. Each number lies between the range of 0 – 255, for example: 192.168.1.1. IP
address of the web server is also required when the URL of the website hosted on that server is
registered on the World Wide Web.
Web Browser is a software required to access the resources available on the World Wide Web.
Hence, in order to access any website web browser is required. Examples of web browsers are:
Microsoft Internet Explorer, Google Chrome, Mozilla Firefox, Netscape Navigator, etc.
Navigating through the pages of a website is termed as web browsing or surfing.
1.3.3.6 ISP
ISP is the short form for Internet Service Provider. They are basically the organizations
responsible for providing internet connections to the subscribers. Several ISPs also provide space
on their web servers for hosting website of the subscribers.
1.3.3.7 HTML
HTML refers to Hyper Text Markup Language. It is the development language of the websites
available on the web. HTML can be understood as a subset of SGML (Standard Generalized
Mark-Up Language).
1.3.3.8 Hyperlink
Hyperlinks can be understood as the access points to other resources of the same or different
websites. A hyperlink, sometimes referred to as a link, is a clickable element in an electronic
document used to navigate through the linked resources. Typically, you click the hyperlink to
access the linked resource. Hyperlinks can be in the form of clickable textual links, icons,
buttons, etc.
1.3.3.9 DNS
DNS is the short form for Domain Name System. It is used to provide a mapping between the
name of the requested website and its IP address. Usually, user remembers the name or URL of a
website. When user enters this URL in the web browser, a request is sent to DNS for resolving
the entered URL in terms of its IP address. It is the IP address which will be used to locate the
requested resource on the web. The mapping of the URL and the IP address a website is usually
built during the registration of the domain name.
1.3.3.10 W3C
1.3.4 IP Addressing
IP addresses refer to the unique identifier associated with each computer on the internet. These
addresses are also called logical address and are used to uniquely identify the communicating
entities on the internet. IP addresses are provided and managed by the Internet Protocol at the
network layer of the OSI model. IP addresses can be of two types: IPv4 and IPv6.
IPv4 uses a 32-bit address having the address space equal to 232. An address space refers to the
total number of addresses that can be used by the protocol. Figure 1.2 shows the format of an
IPv4 address. Two types of notations have been used to represent an IPv4 addresses:
Binary notation: In this notation, the IPv4 address is represented as sequence of 32 bits divided
into 4 octets. Each octet refers to eight bits or 1 byte. Thus, IPv4 addresses are sometimes
referred to as 4-byte address. Eg: 01110101 10001010 000011101 00000010
Dotted-Decimal notation: In order to facilitate easy reading of the IP addresses, they are
sometimes written as a sequence of decimal numbers with each byte separated by a period or dot
(.). Eg: 192.168.1.10.
These IPv4 addresses employ the concept of classes. The strategy to classify the address space
into classes is known as classful addressing. This mechanism splits the address space into 5
classes: A, B, C, D, and E. Examining the first few bits of the binary notation or the first byte of
the dotted-decimal notation of the IPv4 address can help in identifying the class to which the
address belongs. Table 1.1 shows the different classes of IP.
In classful addressing, an IPv4 address is composed of two parts: network id and host id. The
length of these parts vary with respect to the corresponding class. This concept is applicable only
for the addresses of class A, B, and C. For the addresses belonging to class A, the first byte
corresponds to network id while the remaining 3 bytes refer to host id. Similarly, for class B, the
first two bytes refer to network id while the remaining two bytes refer to host id. Finally, for
class C, the first three bytes refer to network id while the remaining one byte indicates host id.
It is the responsibility of the Internet Service Provider (ISP) to assign the IP addresses to the
computers communicating on the internet so as to identify the country or region from which a
computer is connecting to the WEB. The assignment of an IP address may be wither dynamic or
static.
Static assignment of IP addresses corresponds to the manual configuration of IP address on the
computers. However, a dynamic assignment employs a DHCP server that has been configured to
automatically provide IP addresses to the connected hosts.
Class Range Binary Notation Dotted Decimal Notation
From To (Range of First Byte)
Class A 1.0.0.0 127.255.255.255 0xxxxxxx xxxxxxxx 0-127
xxxxxxxx xxxxxxxx
Class B 128.0.0.0 191.255.255.255 10xxxxxx xxxxxxxx 128-191
xxxxxxxx xxxxxxxx
Class C 192.0.0.0 192.255.255.255 110xxxxx xxxxxxxx 192-223
xxxxxxxx xxxxxxxx
Class D 224.0.0.0 224.255.255.255 1110xxxx xxxxxxxx 224-239
xxxxxxxx xxxxxxxx
Class E 240.0.0.0 240.255.255.255 1111xxxx xxxxxxxx 240-255
xxxxxxxx xxxxxxxx
Table 1.1: IP address classes
A Router has more than one IP address because router connects two or more different networks.
But A computer or host can only have one and a unique ip address. A routers function is to
inspect incoming packet and determine whether it belongs to local network or to a Remote
Network, if a local packet is determined then there is no need of routing and if a Remote packet
is determined then it will route that packet according to the routing table otherwise the packet
will be discarded. Figure 1.1 shows the format of an IPv4 Address.
The Internet is a worldwide network of networks. As the Internet grew over the years it became
increasingly important to have a governing body, which allocated unique IP addresses to
organizations linked to the Internet. An international body called InterNIC, located in the USA,
is responsible for registering and assigning unique IP addresses to organizations wishing to
manage networks, which will be part of the Internet. A unique IP address therefore points to an
actual computer connected via a gateway to the Internet. This computer is known as a Domain
i.e. a place where information is available. This is a Physical Domain on the Internet.
Conceptually, a Server, which has a permanent IP address (i.e. a Physical Domain), can provide
the following:
• A gateway to other computers to access the Internet
• Information for Internet clients to read
• A physical location on which several Virtual Domains can be hosted
In many cases, when a Web Site provides Internet clients information to read, the site is mounted
as a Virtual Domain on an Internet Server, which is its (host) Physical Domain.
Virtual Domains are identified by a name (e.g. www.microsoft.com). Just like a Physical
Domain needs to have a unique IP address, Virtual Domain Names also need to be unique on the
Internet. All Virtual Domain Names must be registered with InterNIC. One Internet Server may
host several virtual domains. Virtual domains can be conceptualized as sub directories on an
Internet server’s hard disk drive. The information that Internet clients wish to read would be
Files within the sub directory.
When an Internet client connects to an Internet server some software running on the Internet
server must respond to the Internet client’s request for information. The software that runs on an
Internet server and responds to an Internet client’s request for information is called Web Server
software.
An Internet Web server responds to an Internet client’s request for information by going to a
specific sub directory on its hard disk and forwarding a pre-determined file to the Internet client
for the first time. Further, the Web server forwards files to the client depending upon their
corresponding requests. Traditionally, this sub directory on the Internet server is ‘wwwroot’ and
the file automatically picked up and passed to the Internet client for the first time is traditionally
called ‘index.html’.
1.7.3 ISDN
A standard telephone line which works over ISDN requires fully digital signal over copper wire.
So, digital to analog conversion is not required this is in the manner of the working of analog
channel. Two lines called B-lines are offered by most of the telephone companies. It offers the
user the flexibility to use different lines for voice and data, or both lines can be used for higher
data rates of 128kbps. B-ISDN offers transmission rates of 1.5mbps. It requires fibre optics
cable.
Speed: At the time of introduction approximately a decade ago, very significant speed advantage
was offered by ISDN over regular modems, which were further limited to 14.4 Kbps or slower.
At earlier time most of these connections did not exist. It was used by people who required faster
internet access and could not use the leased line. The connection range was approximately from
64kbps to 128kbps. But the speed of ISDN does not come close to that of options such as cable
of xDSL.
1.7.4 VSAT
VSAT (Very Small Aperture Terminal) is a satellite communications system that serves home
and business users. A VSAT user requires a box that interfaces between outside antenna with a
transceiver and the user's computer. A signal is send or received by the transmitter from the
satellite. The earth station is used to send and receive the satellite. Each end user is
interconnected with the hub station via the satellite in a star topology. For one end user to
communicate with another, each transmission has to first go to the hub station which retransmits
it via the satellite to the other end user's VSAT. VSAT handles data, voice, and video signals.
VSAT is signed up by user both by home users who uses a large service such as DirectPC and by
operating a leased line of their own by private companies such as VSAT systems. A number of
advantages over the terrestrial system is provided For private applications, companies can have
total control of their own communication system without dependence on other companies.
Business and home users also get higher speed reception than if using ordinary telephone service
or ISDN.
1.7.5 RF link
A radio frequency (RF) signal refers to a wireless electromagnetic signal used as a form of
communication, if one is discussing wireless electronics. Radio waves are a form of
electromagnetic radiation with identified radio frequencies that range from 3kHz to 300 GHz.
Frequency refers to the rate of oscillation (of the radio waves.) RF propagation occurs at the
speed of light and does not need a medium like air in order to travel. RF waves occur naturally
from sun flares, lightning, and from stars in space that radiate RF waves as they age. Humankind
communicates with artificially created radio waves that oscillate at various chosen frequencies.
RF communication is used in many industries including television broadcasting, radar systems,
computer and mobile platform networks, remote control, remote metering/monitoring, and many
more.
Wireless RF can be a fantastic option for providing high-speed links (up to 100Mb) between
offices in a multisite organisation. It is also a very effective solution in providing broadband
speeds to remote locations or where cabling isn’t easy or available.
This technology will permit linking of company sites together for faster server/email/file access,
or even CCTV access. Wireless RF can also be used for a company’s primary internet
connection.
The benefits of this system are obvious to those customers who suffer because of their remote
location or that have a demand for significant traffic between satellite offices.
The TCP/IP model does not have session or presentation layers. No need for them was
perceived, so they were not included. Experience with the OSI model has proven this view
correct: they are of little use to most applications. On top of the transport layer is the application
layer. It contains all the higher-level protocols. The early ones included virtual terminal
(TELNET), file transfer (FTP), and electronic mail (SMTP). The virtual terminal protocol allows
a user on one machine to log onto a distant machine and work there. The file transfer protocol
provides a way to move data efficiently from one machine to another. Electronic mail was
originally just a kind of file transfer, but later a specialized protocol (SMTP) was developed for
it. Many other protocols have been added to these over the years that includes Domain Name
System (DNS) for mapping host names onto their network addresses, NNTP, the protocol for
moving USENET news articles around, and HTTP, the protocol for fetching pages on the World
Wide Web, and many others.
1.9.4.3 Addressing
TCP/IP assigns each computer on the network a unique address called its IP address. Thus, every
computer on the network is uniquely identifiable and information could be sent to it by simply
addressing its IP address. The present implementation of IP addressing is known as IPv4, while a
newer implementation supporting a much larger number of unique addresses called IPv6 is being
developed to replace IPv4.
1.9.4.4 Connection
Communication with TCP/IP starts with a connection being established between the two
computers. This is achieved in a systematic manner, called the three-way TCP handshake. The
computer initiating the communication sends a connection request packet to the other computer.
If the computer is the one with the correct IP address, it sends a packet back. If the first computer
receives that packet, it sends another one to the second computer, the reception of which by the
latter establishes a connection. The information is then exchanged using this established
connection, reducing the risk of the data being compromised.
Browser Vendor
Netscape Communications
Netscape Navigator
Corp.
Safari Apple
2.0 Objective
HTML, an acronym for Hyper Text Markup Language, specifies how the structure of a webpage
will be with the help of various markups. The following unit explains the core concepts of
HTML such as its structure, elements, attributes and core events. It also sheds light on block-
level elements and text-level elements. With the help of this unit, the reader will be able to
understand the basic elements used in HTML and their usage in the formatting of a webpage.
2.1 HTML
HTML, an acronym for Hyper Text Markup Language, specifies how the structure of a webpage
will be with the help of various markups. It is a structured markup language that is used to create
Web pages. Markup languages like HTML bundle together codes which are elements that are
used to represent the structure and format of a document. A user agent, usually a Web browser
which renders (delivers) the document, interprets the meaning of these codes to decipher
(making it into simpler human readable text) how to structure or display a document. The HTML
elements are made up of alphanumeric tokens surrounded by angle brackets, for example, <B>,
<HTML>, <IMG> and <HR> .
Almost all elements possess a pair of tags i.e. a start tag and an end tag. The start tag is a
mnemonic symbol for the element enclosed in ‘<’ ’>’, also known as angle brackets, for
instance, the symbol associated with bolding text is B and the start tag for this purpose is <B>.
An end tag is the same as that for a start tag, but with an exception that there exists a forward
slash preceding the text symbol of start tag: </B>. The instruction applied by an element
modifies whatever content is present between the starting and ending tags:
This is an example of a simple HTML document.
Example:
Sample of Heading 1
Sample of Heading 2
Sample of Heading 3
Sample of Heading 4
Sample of Heading 5
Sample of Heading 6
Example:
Output:
2.3.2 PARAGRAPHS
The <p> tag provides a means to structure our text into different paragraphs. Each paragraph
should write in between an opening <p> and a closing </p> tag as shown below in the example.
Example:
For our and others convenience, it is better to put few blank lines between paragraphs to edit in
future or on demand.
2.3.3 PREFORMATTED TEXT
The preformatted text tag <pre> used to display the same text in our document as it is written in
HTML script. The font-width, their spaces, lines and tabs of our source document remain as is it.
In simple words, the browser shows our text as we typed it in. Through monospace font, the text
is rendered where the same amount of space is occupied by all characters. Visually, preformatted
text looks like a courier font. This is an example of preformatted tag.
Example:
Output:
Example:
<b>boldface</b>
<u> underline</u>
<i>italic</i>
Output:
boldface
underline
italic
2.3.5 LISTS
In HTML, we can give number, unnumbered and lists to the different text using the simple tags.
We can also use nested lists with a list. HTML editor automatically takes the space between the
bullet or list number in a text, we do not need to mention it. Neither (as yet) do we have control
over what type of bullet will be used as each browser is different.
Unnumbered lists:
<ul> tag is use to unnumbered any list followed by the actual list items, which are marked with
the <li> tag. The list is ended with the ending tag </ul>.
<!DOCTYPE html>
<html>
<body>
<h2>Disc bullet with Unordered list </h2>
<ul style="list-style-type:disc">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ul>
</body>
</html>
Output disc:
• Ram
• Shyam
• Mahesh
<!DOCTYPE html>
<html>
<body>
<h2>Circle bullets with Unordered list </h2>
<ul style="list-style-type:circle">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ul>
</body>
</html>
Output:
o Ram
o Shyam
o Mahesh
<!DOCTYPE html>
<html>
<body>
<h2> Square Bullets with Unordered list </h2>
<ul style="list-style-type:square">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ul>
</body>
</html>
Output:
▪ Ram
▪ Shyam
▪ Mahesh
Numbered lists
Similar example given here using a numbered list format:
Example Numbers:
<!DOCTYPE html>
<html>
<body>
<h2>Numbers are used for Ordered List</h2>
<ol type="1">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ol>
</body>
</html>
Output:
1. Ram
2. Shyam
3. Mahesh
<!DOCTYPE html>
<html>
<body>
<h2>Letters are used for Ordered List </h2>
<ol type="A">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ol>
</body>
</html>
Output:
A. Ram
B. Shyam
C. Mahesh
<!DOCTYPE html>
<html>
<body>
<h2> Lowercase Letters are used for Ordered List </h2>
<ol type="a">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ol>
</body>
</html>
Output:
a. Ram
b. Shyam
c. Mahesh
This is an example of roman letters.
Example Roman letters:
<!DOCTYPE html>
<html>
<body>
<h2> Roman Numbers are used for Ordered List </h2>
<ol type="I">
<li>Ram</li>
<li>Shyam</li>
<li>Mahesh</li>
</ol>
</body>
</html>
Output:
I. Ram
II. Shyam
III. Mahesh
2.3.6 BLOCKQUOTE
For a long quotation in the text, we can use a < blockquote > tag and the text enclosed within this
tag indicates an extended quotation. Blockquote texts are generally rendered by the browser as
indented text. It looks like this:
<blockquote>...</blockquote>
The <title> is an important tag which required to shown the title of the HTML documents and it
only contains text and other tags containing in the title are ignored. The title is displayed in the
browser’s toolbar. It also shows the favorite pages title which we added during browsing and in
search-engine results title.
Example:
<!DOCTYPE html>
<html>
<head>
<title> First HTML script for web page </title>
</head>
<body>
First HTML script for web page
</body>
</html>
Output:
Footer definition and Usage
The <footer> tag in HTML represents a footer for a document or section. A <footer> element
generally contains information about its author, copyright data or links to other related
documents. You can have several <footer> elements in one document.
Example:
<!DOCTYPE html>
<html>
<body>
<footer>
<p>Posted by: xyz</p>
<p>Contact information: <a href="mailto:[email protected]">[email protected]</a>.</p>
</footer>
<p><strong>Note:</strong> The footer tag is supported only from Internet Explorer 9 and later
versions.</p>
</body>
</html>
Output:
Example:
<!DOCTYPE html>
<html>
<body>
<p> Example of a simple text.</p>
<p><b> Example of a bold text.</b></p>
</body>
</html>
Output:
The HTML <i> tag represents italic text, without any extra importance.
<!DOCTYPE html>
<html>
<body>
<p>Example of a simple text.</p>
<p><i>Example of a italic text.</i></p>
</body>
</html>
Output:
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML <small>Small</small> Formatting</h2>
</body>
</html>
Output:
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML <mark>Marked</mark> Formatting</h2>
</body>
</html>
Output:
The HTML <del> tag used to highlight the deleted (removed) text.
Example:
<!DOCTYPE html>
<html>
<body>
<p>The del tag defines deleted (removed) text.</p>
<p>I like to play <del>Cricket</del> Football.</p>
</body>
</html>
Output:
2.6 Text Style
The appearance of an HTML page can be changed with the style attribute.
The syntax of the HTML style attribute is given below:
<tagname style="property:value;">
The property is a CSS property (Cascading Style Sheet, used for enhancing the look of any
document). The value is a CSS value.
We can set the background color of any HTML page by using the background-color property.
The below example shows how to set the background color of a page to powder blue:
Example:
<!DOCTYPE html>
<html>
<body style="background-color:powderblue ;">
<h1>Example of Background Color changing.</h1>
<p>Example of Background Color changing.</p></body>
</html>
Output:
Example:
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;">Example of Blue color text.</h1>
<p style="color:red;">Example of Red color text.</p>
</body>
</html>
Output:
The size of the font in a HTML document can be set according to our requirement by using font-
size property and it is illustrated below with a simple example:
Example:
<!DOCTYPE html>
<html>
<body>
<h1 style="font-size:300%;">The font size is very large.</h1>
<p style="font-size:160%;">The font size is big.</p>
<p style="font-size:60%;">The font size is small.</p>
</body>
</html>
Output:
2.6.4 HTML Text Alignment
For alignment of the text of HTML pages, there are four text-align property (left, center, right
and justify) that are frequently used. It defines the horizontal text alignment for an HTML
element. The example given below shows the method for center alignment text:
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Output:
Example:
Output:
Example:
Output:
In the beginning, graphics was not supported by the web pages only texts are used. But later on
images and other types of multimedia files are embedded with web pages. The graphics are
embedded in a HTML pages using a simple tag which is represented by <IMG>. We can also
embed the images inside other elements such as anchors. When embedded inside an anchor, then
the user left clicks on the image, they will go to the designated link (rather, their browser will
load a file from the designated link). The <IMG> element has no ending tag. The syntax of
embedding an image is follows:
<img src=”tree.jpg”>
Here, src attributes defines a path pointing to the image from where we want to embed.
IMG Attributes
Output:
2.8 Tables
An HTML <table> tags are used to create different table in our web pages. Each table row is
defined with the <tr> tag. A table header is defined with the <th> tag. By default, table headings
are bold and centered. A table data/cell is defined with the <td> tag. This is an example of
HTML table with border where border width is 1.
Example:
<!DOCTYPE html>
<html>
<Body>
<table border="1">
<tr>
<th>Student Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Ram</td>
<td>HTML</td>
<td>87</td>
</tr>
<tr>
<td>Shyam</td>
<td>HTML</td>
<td>73</td>
</tr>
</table>
<Body>
</html>
Output:
Tag Description
<table> Displays a table
<th> Represents a header cell in a table
<tr> A row in a table
<td> A cell in a table
<col> Specifies column properties for each
column within a <colgroup> element
<caption> A table caption
<colgroup> Specifies a group of one or more
columns in a table for formatting
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table
Example:
<html>
<body>
<table style="width:100%">
<tr>
<th>Student Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Ram</td>
<td>HTML</td>
<td>87</td>
</tr>
<tr>
<td>Shyam</td>
<td>HTML</td>
<td>73</td>
</tr>
<tr>
<td>Ghanshyam</td>
<td>HTML</td>
<td>67</td>
</tr>
</table>
</body>
</html>
Output:
2.8.4 HTML Table - Adding Cell Padding
To manage the spaces between the cell of a table and its border, we use Cell padding tags. If we
do not mention a padding, the table cells will be displayed without padding. This is an example
of a cell padding.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 20px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Student Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Ram</td>
<td>HTML</td>
<td>87</td>
</tr>
<tr>
<td>Shyam</td>
<td>HTML</td>
<td>73</td>
</tr>
<tr>
<td>Ghanshyam</td>
<td>HTML</td>
<td>67</td>
</tr>
</table>
<p>Try to change the padding to 15px.</p>
</body>
</html>
Output:
In a web page, several links are used to directly access the other pages or other parts of a given
page. These links are also known as hyperlinks which allows user to switch between different
web pages. When we move the mouse over a link, the mouse arrow will turn into a little hand.
Note: A link does not have to be text. It can be an image or any other HTML element.
Other tags
• <a> tag is an anchor tag which represents a link to reach the new linked document.
• href attribute is used to link the address of the web pages by url.
• target attribute to define where to open the linked document
• <img> tag (inside <a>) to use an image as a link
• id atribute (id="value") to show a bookmarks in web page
• href attribute (href="#value") to link to the bookmarks
<a href="/html/default.asp">HTML tutorial</a>
Example:
<!DOCTYPE html>
<html>
<body>
<p><a href="https://www.google.com">Visit google website</a></p>
</body>
</html>
Output:
2.10 Frames
In HTML pages, frames allow multiple views to the user and we can browse window into
multiple sections with a separate HTML document. A browser contains many frames in a
window which is known as a frameset. The window frames are divided into rows and columns
in similar way as table are organized.
Disadvantages of Frames
Due to some major drawbacks of frame in window, it is never recommended to use frames in
our webpages −
• In smaller screen, frames do not cop-up properly because their screen is not big enough
to be divided up.
• Sometimes our page will be displayed differently on different computers due to different
screen resolution.
• The browser's back button might not work as the user hopes.
• There are still few browsers that do not support frame technology.
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag
defines how to divide the window into frames. The rows attribute of <frameset> tag defines
horizontal frames and cols attribute defines vertical frames. Each frame is indicated by <frame>
tag and it defines which HTML document shall open into the frame.
2.11 Summary
HTML is a structured programming language (Structured programming is paradigm aimed at
improving the clarity, quality, and development time of a computer program) which provides a
set of rules for correct application of elements. The browser renders (display) the HTML code
for correct representation and orientation of content. At times, the rules laid down in HTML are
interpreted differently by browser which provides the programmers an opportunity to exploit this
vulnerability. HTML is essentially a tag-based language. The documents start with the
<! DOCTYPE> tag. The entire document is encapsulated within <HTML> (opening and closing)
tags. The document is further divided into header and body sections specified by <HEAD> and
<BODY> tags, respectively. The header section is used to provide the descriptive information
related to the web document and needs to contain the <TITLE> tag to define the title of the page.
The body section of the web document contains information regarding placement of various
elements of the document. Block-level elements, text-level elements, and special-character
entities are used to structure it. Some tags are used for providing certain logic and the others are
for physical representation. The HTML elements discussed so far are of basic nature and are
widely used over all systems. They are utilized to customize the document presentation.
However, a complete look of the web document cannot be achieved simply using these basic
tags.
3.0 Objective
JavaScript is an object-oriented programming language. It is used to create dynamic HTML
webpages. It provides open and cross platform. In this unit, you will study about the various data
types, variables, operators, which are used in JavaScript. You will also gain understanding of
looping in control structure and conditional statements like if-else. In the later sections, you will
be introduced with the concepts of functions in JavaScript.
In JavaScript, interaction with server is less. Because user input can be validated before sending
to the server so load on the server would be less. It provides feedback to visitors immediately. It
increases the interactivity and it can have rich interfaces by including items like drag and drop
components and sliders.
JavaScript has some limitations such as the reading and writing of files are not allowed by client-
side JavaScript. Networking applications does not use JavaScript. Multithreading or
multiprocessor capabilities are not present in JavaScript.
Two trivial data types are defined in JavaScript: null and undefined, each of them
defines only a single value. Along with these primitive data types, JavaScript supports a
composite data type known as object.
Note: Floating-point values are used to represent all numbers in JavaScript. There is none of the
difference between integer and floating-point values.
3.4.2 Literals
A fixed value in any source code is known as Literal. Atomic values for integers, floating point
numbers and strings and generally for Booleans and characters are treated as literals.
Numeric Literals
All numeric literals are values of type Number. The Number type values are represented
internally in double-precision floating-point form. Because of this single numeric data type,
numeric values in JavaScript are often called numbers. Numeric literals can have either integer
or floating-point values in a script. Stings of digits are Integer literals. Decimal points,
exponents, or both can be considered as floating-point literals. An uppercase or lowercase 2 and
a possibly signed integer literal are specified as Exponents.
Valid numeric literals are as following:
53 5.3 .53 53. 5E3 5e3 .5e3 5.e3 5.3E-3
Integer literals can be written in hexadecimal form by preceding their first digit with either 0x or
0X. (The first character is zero, not “oh”.)
String Literals
A string literal is a sequence of zero or more characters delimited by either single quotes (‘) or
double quotes (“). Characters which are specified with escape sequences (i.e. /n or /t) can be
included in string literals. An actual single-quote character in a single literal which is delimited
by single quotes, then the embedded single quote must be preceded by a backslash:
Boolean Literals
Boolean literals are logical values that have only one of two values, true or false. The values as
yes or no, on or off, or 1 or 0 can be considered as Boolean literals. They are used to test whether
a condition is true or false. The value true evaluates to 1 and false evaluates to 0, when using
numeric comparison and equality operators.
Example:
output1 = true
or
if (output2 == false) {do something;}
3.5 Variable
In JavaScript, variables are present like several programming languages have. It can be
considered as named containers. These containers accommodate the data and then container can
be used to refer data by naming it.
Variable must be declared before using it in a JavaScript program. The declaration of variable is
as follows.
script type="text/javascript">
<!--
var cost;
var name;
//-->
</script>
You can also declare multiple variables with the same var keyword as follows:
<script type="text/javascript">
<!--
var cost, name;
//-->
</script>
Variable initialization stores a value in a variable. Variable initialization can be done at the time
of creation or when it is needed.
For instance, variable named cost might be created and assign the value 400.20 to it later. Here a
value can be assigned at the time of initialization for the variable name as shown in below.
<script type="text/javascript">
<!--
var name = "Ram";
var cost;
cost = 400.20;
//-->
</script>
Note: For declaration or initialization purpose var keyword is used, variable name is defined
only once in a document.
3.5.1 Variable Scope
A section of a program in which a variable is defined is called scope of that variable. In
JavaScript two types of variables are present.
• Global Variables: It can be defined anywhere in JavaScript code. Because it has global
scope.
• Local Variables: It will be defined in a function and any changes or manipulation will
affects it only within a function.
Precedence is given to local variables over a global variable with the same name. Global variable
will be hidden if a local variable is declared with the same name as a global variable. It can be
easily understand by the following example.
<script type="text/javascript">
<!--
varVar1 = "global"; // Declare a global variable
function findscope( ) {
varVar1 = "local"; // Declare a local variable
document.write(Var1);
}
//-->
</script>
3.7 Operator
Operators are symbols that are used to perform operations on operands. For example, there is an
expression8-2 is equal to 6. In this example, operands are 8 and 2 and operator is ‘-’.
The following type of operators is supported by JavaScript.
• Arithmetic Operators
• Comparison Operators
• Bitwise Operators
• Logical (or Relational) Operators
• Assignment Operators
• Conditional (or ternary) Operators
Note: Addition operator (+) can be used for both Numeric and Strings. e.g. "s" + 5 will produce
result as "s5".
5 Left Shift (<<) Binary left shift operator. The (B << A) is 48.
left operands value is moved
left by the number of bits
specified by the right operand.
Note: Same logic is applied to Bitwise operators, so they will become <<=, >>=, >>=, &=, |=
and ^=.
3.7.6 Miscellaneous Operators
Two operators, which are quite useful in JavaScript, are discussed here:
i. The Conditional Operator (? :)
ii. The typeof Operator
Conditional Operator (? :)
Conditional operator is used to evaluate an expression that either it is true or false value and later
one of the two given statements is executed depending upon the output of the evaluation.
Example:
The following code can be used to understand the working of the Conditional Operator in
JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var x = 2;
var y = 3;
var newline = "<br />";
document.write ("((x > y)? 20 : 30) => ");
output = (x > y) ? 20 : 30;
document.write(output);
document.write(newline);
document.write ("((x < y)? 20 : 30) => ");
output = (x < y) ? 20 : 30;
document.write(output);
document.write(newline);
//-->
</script>
<p> Use the different values of variables and then try...</p>
</body>
</html>
Output:
((x > y) ? 20 : 30) => 30
((x < y) ? 20 : 30) => 20
Use the different values of variables and then try...
Syntax
The syntax of the while loop in JavaScript is as follows:
while (expression)
{
Statement(s) to be executed for true expression
}
Example
The following example can be used to implement while loop.
<html>
<body>
<script type="text/javascript">
<!--
var count = 0;
document.write("Initialize Loop ");
while (count < 5){
document.write("Current Count : " + count + "<br />");
count++;
}
document.write("Loop terminated!");
//-->
</script>
<p> Use the different values of variables and then try...</ p>
</body>
</html>
Output
Syntax
The syntax for do-while loop in JavaScript is as follows:
do{
Statement(s) to be executed;
} while (expression);
Note: At the end of the do...while loop, the semicolon must be used.
Example
The following example shows the implementation a do-while loop in JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var count = 0;
document.write("Initialize Loop" + "<br />");
do{
document.write("Current Count : " + count + "<br />");
count++;
}while (count < 5);
document.write ("Loop terminated!");
//-->
</script>
<p> Use the different values of variables and then try...</p>
</body>
</html>
Output
Initialize Loop
Current Count : 0
Current Count : 1
Current Count : 2
Current Count : 3
Current Count : 4
Loop terminated!
Use the different values of variables and then try...
All the three parts can be put in a single line separated by semicolons.
Syntax
The syntax of for loop is JavaScript is as follows:
Example
The following example tells working of for loop in JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var count;
document.write("Initializing Loop" + "<br />");
for(count = 0; count < 5; count++){
document.write("Current Count : " + count );
document.write("<br />");
}
document.write("Loop terminated!");
//-->
</script>
<p> Use the different values of variables and then try...</p>
</body>
</html>
Output
Initializing Loop
Current Count: 0
Current Count: 1
Current Count: 2
Current Count: 3
Current Count: 4
Loop terminated!
Use the different values of variables and then try...
3.9.1 If Statement
The fundamental control statement of JavaScript is ‘If’ statement. It permits JavaScript to make
decisions and execute statements conditionally.
Syntax
if statement has following syntax:
if (expr){
Statement(s) to be executed if expr 1 is true
}
Evaluation of JavaScript’s expression is done here. The given statements will execute, if the
expression is true. Any of the statement will not execute if the expression is false. Usually,
comparison operators are used for making decisions by if statement.
Example
The following example shows the working of if statement in JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var distance = 5;
if( distance> 3 ){
document.write("<b>Use the vehicle</b>");
}
//-->
</script>
<p> Use the different values of variables and then try again...</p>
</body>
</html>
Output
Syntax
The syntax of an if-else statement is as follows:
if (expr)
{Statement(s) to be executed if expr is true
}
else
{Statement(s) to be executed if expr is not true
}
Evaluation of JavaScript expression is done here. If the expression is true, than the ‘if’ block
statement(s) will be executed. Otherwise, the else block statement(s) will be executed.
Example
The following program shows the implementation of the if-else statement in JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var distance = 2;
if( age > 3 ){
document.write("<b>Use the vehicle</b>");
}else{
document.write("<b>Don’t use the vehicle</b>");
}
//-->
</script>
<p> Use the different values of variables and then try again...</p>
</body>
</html>
Output
Syntax
A Nested if-else statement has the following syntax:
if (expr 1){
Statement(s) to be executed if expr 1 is true
}else if (expr 2){
Statement(s) to be executed if expr 2 is true
}else if (expr 3){
Statement(s) to be executed if expr 3 is true
}else{
Statement(s) to be executed if no expr is true
}
Statement(s) are executed based on the true condition. Else block is executed when no condition
is true.
Example
The following program shows the implement of an if-else-if statement in JavaScript.
<html>
<body>
<script type="text/javascript">
<!--
var branch = "cse";
if( branch == "me" ){
document.write("<b>Mechanical</b>");
}else if( branch == "cse" ){
document.write("<b>Computer Science</b>");
}else if( branch == "ee" ){
document.write("<b>Electrical</b>");
}else{
document.write("<b>Civil</b>");
}
//-->
</script>
<p> Use the different values of variables and then try again...</p>
</body>
</html>
Output
Computer Science
Use the different values of variables and then try again...
3.10 Array
JavaScript arrays stores multiple values in a single variable.
Example
var books = ["C", "Python", "JavaScript"];
• An array is a special variable. More than one value can be held by an array at a time.
• If a list of items (i.e. a list of books) is stored books in a single variable then it could look
like this:
var book1 = "C";
var book2 = "Python";
var book3 = "JavaScript";
• Here we have to store very less number of items, if we need to store more number of
items or we want to loop through and find a specific item value, then there is need of
array.
• In array, we can store many values under a single name, and index number is referred to
access the values.
Create an Array
Syntax:
var arrname = [item1, item2, ...];
Example
var books = ["C", "Python", "JavaScript"];
Example
var cars = new Array("C", "Python", "JavaScript");
Exactly same is done in the previous examples. There is no need to use new Array ().
The first one (the array literal method) is better to use for simplicity, readability and execution
speed.
Example
var books = ["C", "Python", "JavaScript"];
document.getElementById("demo").innerHTML = books[0];
The array name can be referred to access the complete array in JavaScript.
Example
var books = ["C", "Python", "JavaScript"];
document.getElementById("demo").innerHTML = books;
3.10.2Array as Objects
Arrays are a special type of objects. For arrays, “objects” is returned by the typeof operator in
JavaScript. But, arrays are the best way to explain JavaScript arrays.
Numbers are used by arrays for access its "elements". In this example, student[0] returns Mark:
Array:
var student = ["Mark", "Juke", 23];
Objects use names to access its "members". In this example, student.fName returns Mark:
Object:
var student = {fName:"Mark", lName:"Juke", age:32};
Example
The length property of an array returns the length of an array (the number of array elements).
Example
• The length property is always one more than the highest array index.
•
Looping Array Elements
The use of “For” loop is the best way to loop through an array.
Example
Example
var books = ["C", "Python", "JavaScript", "Perl"];
books.push("HTML"); // adds a new element (HTML) to books
Example
Note: Undefined “holes” can be created in an array if elements are added with high indexes.
Example
var books = ["C", "Python", "JavaScript", "Perl"];
books[6] = "HTML"; // adds a new element (HTML) to books
Example
Note:
The array is redefined to a standard object in JavaScript, if named indexes are used. After that,
some array methods and properties can produce the incorrect results.
Example
3.11 Functions
A group of reusable code that can be called anywhere in the program, is defined as Function. By
using function, there is no need of writing the same code repeatedly. It helps programmers in
writing modular codes. By using functions, programmer is allowed to divide a big program into a
number of small and manageable functions.
Like any other advanced programming language, all the features necessary to write modular code
using functions is supported by JavaScript. There are functions such as alert () and write () are
used repeatedly but they had been written in core JavaScript exactly once.
JavaScript allows us to write our own function in. This part tells that how you can to write your
own functions in JavaScript.
Syntax
The syntax is as follows:
<script type="text/javascript">
<!--
function function_name(parameter-list)
{
statements
}
//-->
</script>
Example
A function called sayHello which takes no parameters is defined in the following example:
<script type=”text/javascript”>
<!--
function sayHello()
{
alert("Hello there");
}
//-->
</script>
Calling a Function
You would need to write the name of that function to invoke a function somewhere later in the
script, as shown in the following program.
<html>
<head>
<script type="text/javascript">
function sayHello()
{
document.write ("Hello there!");
}
</script>
</head>
<body>
<p>Click the following button to call the function </p>
<form>
<input type="button" onclick="sayHello()" value="Say Hello">
</form>
<p>Set the different text in write method and then try...</p>
</body>
</html>
Output
Example
Our sayHello function is modified in this example. Now it takes two parameters.
<html>
<head>
<script type="text/javascript">
function sayHello(branch, year)
{
document.write (branch + " is " + year +);
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="sayHello('CSE', 2)" value="Say Hello">
</form>
<p>Set different parameters inside the function and then try...</p>
</body>
</html>
Output
An optional return statement can present a JavaScript function. This is required to return a value
from a function. This statement should be the last statement in a function.
For example
In a function, if two numbers are passed and then it can be expected that the function will return
their addition in the calling program.
Example
The following example defines a function that takes two parameters and concatenates them
before returning the output in the calling program.
<html>
<head>
<script type="text/javascript">
function concatenate(first, last)
{
var full;
full = first + last;
return full;
}
function secondFunction()
{
varoutput;
output = concatenate('Ram', 'Sita');
document.write (output );
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="secondFunction()" value="Call Function">
</form>
<p>Set different parameters inside the function and then try...</p>
</body>
</html>
Output
Before the JavaScript 1.2, function definition was allowed only in top-level global code, but
JavaScript 1.2 allows function definitions to be nested within other functions as well. Still
function definitions cannot be appeared within loops or conditionals. These restrictions on
function definitions apply only on function declarations with the function statement.
Function literals (another feature introduced in JavaScript 1.2) may appear within any JavaScript
expression, which means that they can appear within if and other statements.
Example
<html>
<head>
<script type="text/javascript">
<!--
function hypotenuse(a, b) {
function square(x) { return x*x; }
return Math.sqrt(square(a) + square(b));
}
function secondFunction(){
var output;
output = hypotenuse(1,2);
document.write (output );
}
//-->
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="secondFunction()" value="Call Function">
</form>
<p>Use different parameters inside the function and then try...</p>
</body>
</html>
Output
Syntax
The syntax for a function literal is much like a function statement, except that it is used as an
expression rather than a statement and no function name is required.
<script type="text/javascript">
<!—var variablename = function(Argument List){
Function Body
};
//-->
</script>
Syntactically, a function name can be specified while creating a literal function as follows.
<script type="text/javascript">
<!--
var variable_name = function FunctionName(Argument List){
Function Body
};
//-->
</script>
But this name does not have any significance, so it is not worthwhile.
3.12 Summary
Dynamic HTML webpages can be created using JavaScript. It is light-weighted. JavaScript has
three primitive data types: Numbers, Strings, Boolean. JavaScript has two trivial data types: null
and undefined and a composite data type: Object. Two types of the variable present in
JavaScript: Global and Local variable. Variable initialization stores a value in a variable.
Variable initialization can be done at the time of creation or when it is needed. Scope of a
variable can be defined as a section of a program in which a variable is defined. Operators are
symbols that are used to perform operations on operands. Several operators are present in
JavaScript i.e. Arithmetic, Comparison, Bitwise, Logical, Assignment, Conditional Operators. In
JavaScript, control structure (i.e. loops) is used to minimize the number of lines. The following
loops are used in JavaScript: While, do-while and for loop. Conditional statements are used to
make correct decisions and perform right actions that enable the code. JavaScript arrays stores
multiple values in a single variable. Creation of array, accessing an element. Arrays are special
type of objects. A group of reusable code that can be called anywhere in the program, is defined
as Function. The return statement is used to return a value in a function. Objects are made of
attributes. If an attribute contains a function, it is thought to be a method of the object; otherwise,
the attribute is viewed as a property. A constructor is a function that creates and initializes an
object. A special constructor function called Object() is provided by JavaScript to build the
object.
• Uttam K.Roy. 2010. Web Technologies. New York: Oxford University Press.
• M.Srinivasan. 2012. Web Technology Theory and Practice. India: Dorling Kindersley
Pvt.Ltd.
• David Flanagan. 2011. JavaScript: The Definitive Guide, Sixth Edition. U.S.A.: O’Reilly
Media, Inc.
• Thomas Powell Fritz Schneider. 2012. JavaScript 2.0-The Complete Reference, Third
Edition. U.S.A.: McGraw-Hill/Osborne
UNIT 4: Understanding XML
UNIT STRUCTURE
4.1. Objective
4.2. SGML
4.3. XML
4.4. XML and HTML
4.5. Modelling XML Data
4.6. Styling XML using XSL
4.7. XHTML
4.8. Summary
4.9. Question for exercise
4.10. Suggested reading
4.1 Objective
XML stands for Extensible Markup Language. It is a new markup language, developed by the
W3C (World Wide Web Consortium), mainly to overcome the limitations in HTML. This unit
outlines the basic concepts of XML. The chapter explains the need of XML as well as what
XML is good at. Upon completion of this unit, the readers shall be able to understand what are
markup languages, the relationship between SGML, XML and HTML, the benefits of using
XML, the various constructs of XML that are used to achieve the required objectives as well as
typical applications of XML
4.2 SGML
Standard Generalized Markup Language (SGML) has been developed and standardized by the
International Organization for Standardization (ISO) in 1986. SGML is a generalized standard
since it does not require any specific system, device and language. A markup language uses a set
of additional items called markups to create a document of hierarchical structure. SGML itself is
not a markup language. It is used for defining and structuring other document markup languages
such as HTML and for specifying the rules for tagging elements in a document. Hence, SGML
can be considered as a specification for embedding descriptive markup within a document.
SGML considers the semantics and other auxiliary components of the document for structuring
the document without specifying the graphical design of the document. The actual graphical
styling of such a document may vary, depending on the yield medium and style inclinations. The
advantages of SGML based documents:
• They can be made by considering document structure rather than appearance qualities (which
may change after some time).
• The document will be more portable as SGML compiler can interpret any document using
the reference to its document type definition (DTD).
Documents initially planned for the print medium can be re-adjusted to other media, for example,
computer display screen.
The language utilized by Web browser, Hypertext Markup Language (HTML), is a case of an
SGML-based language. The document structure is written in a Document Type Definition
(DTD) sometimes also referred to as SGML application. A DTD specifies a set of elements, their
relationships, and the tag set to mark the document.
The SGML approach is not to impose its own tag set but to propose a language for authors to
describe the structure of their documents and mark them accordingly. The markup describes the
structure of the document. SGML is an enabling standard, not a complete document architecture.
The strength of SGML is that it is a language to describe documents—in many respects similar
to programming languages. It is therefore flexible and open to new applications.
In today's distributed networking environment, numerous documents are structured as the
Extensible Markup Language (XML) which is an information portrayal language that utilizes
SGML standards. SGML is based on somewhat earlier generalized markup languages developed
at IBM, including General Markup Language (GML) and Information Structure Identification
Language (ISIL).
4.3 XML
XML stands for Extensible Markup Language. It is a text-based markup language derived from
Standard Generalized Markup Language (SGML). A markup language is used to provide
information about a document. XML tags identify the data and are used to store and organize the
data, rather than specifying how to display it like HTML tags, which are used to display the data.
There are three important characteristics of XML that make it useful in a variety of systems and
solutions:
• XML is extensible: XML allows you to create your own self-descriptive tags or language,
that suits your application.
• XML carries the data, does not present it: XML allows you to store the data irrespective
of how it will be presented.
• XML is a public standard: XML was developed by an organization called the World
Wide Web Consortium (W3C) and is available as an open standard.
XML Usage
The rules for writing XML syntax can be broken down into the following components:
1. XML Declaration
2. Elements and Tags
3. Attributes
4. Text
5. References
These components have been discussed in details in the following subsections.
4.3.1.1 XML Declaration
The XML document can optionally have an XML declaration. The XML declaration is the first
line of any XML document. The XML declaration is case sensitive and is written as follows −
<?xml version = "1.0" encoding = "UTF-8"?>
Where version is the XML version and encoding specifies the character encoding used in the
document. The XML recommendation suggests that the declaration should be included in every
XML document.
4.3.1.2 Elements and Tags
XML-elements, also known as XML-tags or XML-nodes are used to structure XML documents.
The names of these elements should be enclosed within the triangular brackets < > as shown
below:
<element-name>
<?xml version="1.0"?>
<employee>
<name>Rajeev
The correct way
< /employee > of using nested elements has been illustrated below:
</name>
<?xml version="1.0"?>
<employee>
<name>Rajeev
< / name >
Root Element:
Every element in an XML document should be the children of a single element, known as the
root element. There can be only one root element in an XML document. The following is not a
correct XML document, because both the x and y elements occur at the top level without a root
element
<x>...</x>
<y>...</y>
<root>
<x>...</x>
<y>...</y>
</root>
attribute_name = "value"
In the above syntax, value has to be in double (" ") or single (' ') quotes. Here, attribute1 and
attribute2 are unique attribute labels.
<person age="35">
<name>Amit</name>
<gender>male</gender>
</person>
Attributes are used to distinguish among elements of the same name, when you do not want to
create a new element for every situation. Hence, the use of an attribute can add a little more
detail in differentiating two or more similar elements.
Attribute Types
The names of XML-elements and XML-attributes are case-sensitive, which means the name of
start and end elements need to be written in the same case. To avoid character encoding
problems, all XML files should be saved as Unicode UTF-8 or UTF-16 files.
Whitespace characters like blanks, tabs and line-breaks between XML-elements and between the
XML-attributes will be ignored.
Some characters are reserved by the XML syntax itself. Hence, they cannot be used directly. To
use them, some replacement-entities are used, which are listed below:
Characters NOT Allowed Replacement Description
< < Less than
> > Greater than
& & Ampersand
‘ ' Apostrophe
“ " Quotation mark
4.3.1.6 Comments
XML comments have the following linguistic structure:
<h2>Relationship speed-distance</h2>
<i> D = S × T </i>
In XML
<equation>
<meaning>Relationship speed-distance</meaning>
<leftside> D </leftside>
<rightside> S × T </rightside>
</equation>
The main structure of an XML document is tree-like, and most of the lexical structure is devoted
to define that tree, but there is also a way to make connections between arbitrary nodes in a tree.
For example, in the following document, there is a root node with three children, one of the
children has a link to the other children:
<p>
<q id="x7">1st q</q>
<q id="x8">2nd q</q>
<q href="#x7">3rd q</q>
</p>
The last q has an `href’ attribute and it points to an element with the same `id’ as that of the first
q, so the third q points to the first. (Note that this is a generalization of a similar mechanism in
HTML) The linking model is explained in the XML-link draft.
The tree that an XML document represents has a number of different types of nodes:
a) element
b) document
c) processing instruction [not needed?]
d) comment
e) data
Such an element node has a type p, an ordered list of children ci, and a set of attributes, which
are pairs of attribute names ai and attribute values Ai. In contrast to the children, the order of the
attributes doesn’t matter. Thus, the same node can be linearized with different expressions.
Furthermore, all the ai are different, but the Ai don’t have to be. Note that if m=0, the two
expressions above are equivalent, and indeed one can use either one at will. The type, attribute
names and attribute values consist of strings of characters. There are restrictions on the lexical
structure of the type and attribute names: they must consist of (Unicode) letters, (Unicode) digits,
dashes and dots, they must be at least one character long and they must start with a letter or a
dash. There are no restrictions on attribute values, in particular they may be empty (but see under
`Escape mechanism’ below). The attribute name “id” (upper or lower case) is reserved for
something called the ID of the element. Furthermore, attribute names may not start with the four
letters “xml-“ (upper or lower case), as these are also reserved for xml-link.
A processing instruction (PI) node is always a leaf node. It only has an instruction i associated
with it. The instruction is a sequence of zero or more characters, without any restrictions, except
that the sequence might not start with the three characters `xml’ (upper, lower or mixed case)
followed by a space or newline. It looks like this in the XML document: <?i?>
Processing instructions that start with `xml’ + whitespace have special meaning to XML. They
look like this: <?xml i?>
A comment node is similar to a processing instruction. It is also a leaf node and has only
a comment c: <!—c
The intention is that comment nodes are used to include explanatory notes for human
consumption, while processing instructions are for consumption by some application. In the
XML data model, however, there is no difference between them (apart from the processing
instructions that start with `<?xml’).
Data nodes are also leaf nodes. They have a single characteristic: the data d. Since all the other
nodes have delimiters to distinguish them, data nodes don’t need them. Everything that is not
between `< and `>’ is data. (With one exception, at certain places newlines may be inserted for
the benefit of people editing XML by hand, and those newlines are not part of any node.) Data
nodes cannot be empty, that is, their data characteristic contains at least one character.
4.7.1 XSL
XSL is a language used to express style sheets. An XSL style sheet describes how to display an
XML document of a given type. XSL shares the functionality and is compatible with CSS2
(although it uses a different syntax). It also adds a transformation language for XML documents
called XSLT. Originally, intended to perform complex styling operations, is now widely used as
a general-purpose XML processing language. XSLT is thus used for purposes other than XSL,
like generating HTML web pages from XML data, advanced styling features, expressed by an
XML document type which defines a set of elements called Formatting Objects, and attributes
(in part borrowed from CSS2 properties and adding more complex ones.
4.7.2 XSLT
The Extensible Stylesheet Language Transformation (XSLT) is used for transforming XML
documents into XHTML documents or to other XML documents. Data transformation
means parsing an input XML document into a tree of nodes. Transformation is about data
exchange.
Before designing a XSLT document, we will go through the mostly used XSLT elements and
attributes. The prefix xsl: specifies the XSLT elements. The following are some XSLT elements:
• Xsl: stylesheet: Specifies that the document is a XSL stylesheet. This element defines the
namespace to access the XSLT elements and attributes. Example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform
Xsl: template: Declare the HTML template. It uses the Match attribute to search in the
XML document. Here “/” means it is for the entire document. Example:
Xsl if: implements an if-else condition. Assume I want to display some example based on
condition then this element helps. Example:
xsl: sort: sorts the XML data based on a node name. It selects an attribute to provide the
node name. The following exmple is sorting the data ordered by the artist XML node's
value. Example:
<xsl:sort select="artist"/>
xsl: choose: implements a Switch-case in XSLT. Inside the choose element it uses
a when element to check the values. Inside the when element it uses a test attribute to
define the condition for the case. Example:
<xsl:choose>
<xsl:when test="price > 10">
……
</xsl:when>
</xsl:choose>
xsl: for-each: iterates over XML data. Assume I have multiple tutorial nodes present in
some XML data then this element helps. Example:
<xsl:for-each select="tutorials/tutorial">…</xsl:for-each>
In the preceding xslt file we loop over (<xsl:for-each) a XML node (tutorials/tutorial) and
display the data inside the div with the designed format. It creates a div depending on whether
there are no tutorial nodes found inside the XML data. Now we need to add a reference xslt file
inside the XML file (tutorial.xml).
See the Yellow marked code that will be additional code. Now the updated code XML will be:
Browse the XML file to see how the data looks in the browser. Please see the following
screenshot:
Figure 4.2: Output of XML data using XSLT
4.8 XHTML
Extensible HyperText Markup Language (XHTML) was developed by W3C (World Wide Web
Consortium) in order to facilitate the developers for making the transition from HTML to XML.
It can be understood as HTML redesigned as XML. The XHTML 1.0 is the first document type
in the XHTML family. XHTML is identical to HTML 4.01 with few differences. This is a
cleaner and stricter version of HTML 4.01. Upon migration to XHTML, today web developers
can enter the XML world with all of its benefits, while still retaining confident in the backward
and future compatibility of the content.
➢ Important points to remember while writing a new XHTML document or converting existing
HTML document into XHTML document –
• XHTML document should be initialized with a DOCTYPE declaration.
• The XHTML tags must be closed properly
• The XHTML tags and attributes should be in lower case only.
• There should be proper nesting of all the tags.
• The attribute values should be within quotes.
• Attribute minimization should be avoided.
• The id attribute replaces the name attribute.
• Deprecate the language attribute of the script tag.
The following is the correct XHTML syntax. Difference is that, both the tags are closed properly.
The following table shows a list of the minimized attributes in HTML and the way to write them
in XHTML −
HTML Style XHTML Style
Compact compact="compact"
Checked checked="checked"
Declare declare="declare"
Readonly readonly="readonly"
Disabled disabled="disabled"
Selected selected="selected"
Defer defer="defer"
Ismap ismap="ismap"
Nohref nohref="nohref"
Noshade noshade="noshade"
Nowrap nowrap="nowrap"
Multiple multiple="multiple"
Noresize noresize="noresize"
<a> Should not contain other <a> elements.
<pre> Should not contain the <img>, <object>, <small>,
<big>, <sup> or <sub> elements.
<button> Should not contain the <input>, <select>, <textarea>,
<label>, <button>, <form>, <fieldset>, <iframe> or
<isindex> elements.
<label> Should not contain other <label> elements.
<form> Should not contain other <form> elements.
4.9 Summary
This unit explored the concepts of SGML and XML and their usage in HTML pages. HTML is
the general markup language for the Web. The HTML format text, add graphics, create links,
input forms, frames and tables, etc., and save it all in a text file that any browser can read and
display. XML documents shape a tree structure that starts at "the root" and branches to "the
leaves". All modern browsers have a built-in XML parser that can read and manipulate any XML
document. The DOM (Document Object Model) characterizes a standard way for getting to
XML. The XMLHttpRequest object provides an approach to communicate with a server after a
web page has been loaded. XML Namespaces give a technique to maintain a strategic distance
from component name clashes.
• HTML by Jon Duckett, HTML and XHTML: The definitive guide by O’Reilly media
• XML by O’Reilly media
UNIT- 5: Creation of Dynamic Web Pages using JSP
UNIT STRUCTURE
5.0 Objective
5.1 Dynamic Web Page
5.2 Introduction of JSP
5.3 Pages Overview
5.4 JSP Scripting
5.5 Standard Action
5.6 Page Directive
5.7 Include Directive
5.8 Summary
5.9 Questions for Exercise
5.10 Suggested Readings
5.0 Objective
A server-side dynamic web page is created by using server-side scripts which are processed by
an application server. The application server controls the server-side dynamic web page. The
parameters of the server-side script determine the assembling of every new web page that
incorporates more customer side handling. The following unit explains core concepts of creating
dynamic web pages and introducing the concepts of JSP. It also sheds light on JSP scripting and
page directive. With the help of this unit the reader will be able to create the web pages
dynamically and use various scripting.
Output:
i) <%–JSP Comment–%>: This represent JSP Comments. This tag is used for adding comments
to a JSP page. Further details will be discussed later
Note: Comments starts with a tag <%– and ends with –%>.
ii) The HTML tags like Head, Title and Body are frequently used. The content within these tags
will be delivered in a similar way to client (Web browser).
iii) Scriptlets are the JSP elements that contain Java codes. <%out.print (“Sample JSP code”)
;%> is an example of Scriptlet. Syntax of scriptlet is: <%Executable java code%>. As the java
code ends with semicolon (;), so, the Scriptlets. out.print (“Sample JSP code”) is a java
statement, which prints“Sample JSP code ”.
Both static and dynamic contents are there in dynamic webpages. Static content will have only
text-based formats defined in HTML or XML whereas, the java code embedded inside the
HTML used as JSP tags generates the dynamic content.
Servlets
1. A Servlet is a Java program.
2. Servlets supports HTML tags.
3. It is used for developing the business layer of an enterprise application.
4. Java developers create and maintain the servlets.
JSP
1. JSP program is a HTML code.
2. It supports the java statements by embedding it into HTML using JSP tags.
3. Differentiate the presentation layer and business layer. So, both can be developed
separately easily of an enterprise application
4. Web developers uses JSP frequently used for designing websites.
1) Model 1 Architecture: In case of the Model 1 architecture JSP will play key role. All the
requests made by the client are processed by JSP. A bean object is created by JSP as the client
(web browser) requests. The created object completes the request and passes the response to the
JSP. The response is sent by JSP to the client. In this model, JSP performs most of the
processing. Figure 5.1 represents Model 1 Architecture.
2) Model 2 Architecture: In Model 2, the major role is played by servlets and the client’s (web
browser) request is processed by it. The JSP only takes care of the presentation part (GUI part)
by using bean object created by servlet. Here, the controlling and request processing tasks is
performed by servlet only. The bean object is created by servlet when required by the JSP page
and then calls the respective JSP page as the request made by client. For this type of Model, JSP
doesn’t do any type of processing whereas, Servlet performs all the required processing. Figure
5.2 shows Model 2 Architecture.
Figure 5.2: Model 2 Architecture
5.3.4.1 Translation: In the initial step, the JSP file is converted the web container converts the
into a Java source file containing servlet class definition by the web container. The JSP pages
and tag files are validated by the web container.
5.3.4.2 Compilation: The servlet source code is compiled into a Java class file by the web
container in this step.
5.3.4.3 JSP Page Class Loading: The servlet class byte code is stacked into the web container’s
JVM software using class loader in this step.
5.3.4.4 JSP Page Servlet Instance: An instance of the servlet class is created by the web
container in this step.
5.3.4.5 JSP Page Initialization: The servlet is initialized by calling the jspInit() method by the
web container. As the method is created, it is called immediately. It is called only once during
JSP life cycle.To perform initialization we need to override jspInit() method:
5.3.4.6 JSP Page Service: The requests are now serviced by the initialized servlet. The user
request is processed by calling _jspService () method by the web container. This method is called
for each request during its life cycle. The method takes HttpServletRequest and
HttpServletResponse parameters.
5.3.4.7 JSP Page Destroyed: The JSP servlet instance is being expelled (removed) from the web
containers service by calling the jspDestroy () method which permit JSP page to clean the
resources. This ends the JSP life cycle. This method can be written as follows:
public void jspDestroy()
{
//write your code
}
The time and date of the day is: <%= new java.util.Date () %>
5.3.5.4 The Comment Tag
This tag is used to ignore or hide some parts of the code. The syntax is as follows:
Output:
Total=10
Output:
Explanation
The “new java.util.Date ()” has processed the actual date and time of the HTML on the browser.
Few other examples:
Examples
• This example shows expression for converting lower case string to upper case. Here is
the code:
The Expression: Following expression is used for converting a string to uppercase.
<%= new String(“Hello World”).to Uppercase() %>. A “string” object with value “Hello
World” is created. After that, a Java function “.toUpperCase” is called to convert the string to
upper case.
The HTML: Converting a string to uppercase: HELLO WORLD
• Mathematical expressions can also be used in JSP.
The Expression: 40 multiplied to 5: <%= 40*5 %>. We can easily compute and get answers to
mathematical problems using simple mathematical expressions embedded in our HTML.
The HTML: 40 multiplied to 5: 200.
• Boolean expressions can also be used in JSP.
The Expression: Is 79 less than 65? <%= 79 <65 %>. The return type is always string either
going to be “true” or “false” of these Boolean expressions.
The HTML: Is 79 less than 65? False
Example:
Output:
I love counting: 1
I love counting: 2
I love counting: 3
I love counting: 4
I love counting: 5
Explanation
In the above example, a basic h2 heading has been set up. Then, we have a “for loop” in the
scriptlet. Don’t put in a lot of code in a scriptlet in JSP. It will be easily manageable and
readable. Try refactoring this code into different Java classes and make use of MVC to keep it
under control if we can’t find any other option.
In each iteration of the loop we are printing the “I really love counting” and appending it with
the integer value of the “i” printed through the HTML.
Code:
<%!
String makeItLower(String data)
{
returndata.toLowerCase();
}
%>
Example:
Lower case “My Program” :< %= makeItLower (“My Program”) %>
Output:
Explanation
In the method declaration we are having our standard java method with the return type of a
String. We take a string as an argument and return it converted to a lower case. Later we call this
function through a JSP Expression.
5.5.1.1 Id attribute
If an instance of the Action is created of an object, through the implicit object, it can be
referenced through its id value can be used to it through certain PageContext. The id attribute is
uniquely recognizing the Action element, and enables the action to be referenced inside the JSP
page.
This activity embeds a file at the time requested by the page. Different from
the include directive, at the time the JSP page is translated (converted) it inserts the file into a
servlet. Next follows a table that lists out the properties associated with the incorporate action:
Attribute Description
<html>
<head>
<title>Example of include action</title>
</head>
<body>
<center>
<h3> Example of “include action” </h3>
<jsp:include page = "date.jsp" flush = "true" />
</center>
</body>
</html>
Output:
Once any bean class to be loaded into the page has been loaded, we can jsp: getProperty and
use jsp: setProperty actions for retrieving and modifying the properties of the bean. The table
below lists the attributes of useBean action
Attribute Description
Context for which jsp:setProperty appears is inside jsp:useBean body. The jsp:setProperty is
executed regardless of whether we are executing a new bean or an existing bean is found as
shown below:
Example
On testing the bean class:
/* File: TestBean.java */
package action;
public class TestBean {
private String message = "No message specified";
public String getMessage() {
return(msg);
}
public void setMessage(String msg) {
this.message = msg;
}
}
On Compiling code to generate TestBean.class file which ensure that we copied into C:\apache-
tomcat-7.0.2\webapps\WEB-INF\classes\action path the TestBean.class and the CLASSPATH
variable this folder is ought to be set .This code is used in main.jsp file. This sets/gets the bean
and loads it in a straightforward String parameter:
Output:
Example:
On reusing the files date.jsp and main.jsp.The content of the date.jsp file is:
<html>
<head>
<title> This is index page </title>
</head>
<body>
<center>
<h2> This is index page </h2>
<jsp:forward page = "date.jsp" />
</center>
</body>
</html>
By keeping every one of the document in the directory which is the root and trying to
access main.jsp. The result will be as depicted underneath. Here the content of it is discarded
from the main page and show content from page requested only.
Output:
Example:
We try using some applet for this action. A new <fallback> element, to specify a message can be
used error string to be sent to the user in case the component fails.
Output:
The attributes associated with the page directive are listed below:
Attribute Purpose
Use the accompanying to direct the servlet to compose (write) the output to a buffer of size not
less than 8 kilobytes
Generally, the autoFlush attributes and the buffer are coded on a single page directive as follows:
The accompanying statement directs the browser to render the generated page as HTML:
The accompanying directive sets the content type as a Microsoft Word document
For importing multiple packages, we can specify them separated by comma as follows:
Example
Including a typical header and footer with multiple pages of content is a good example of
include directive. Following three files have been defined below: (a)header.jps,(b)footer.jsp,
and (c)main.jsp.
header.jsp content is as follows:
<%!
int pageCount = 0;
void addCount() {
pageCount++;
}
%>
<% addCount(); %>
<html>
<head>
<title>An example of Include Directive </title>
</head>
<body>
<center>
<h2> An example of Include Directive </h2>
<p>You have visited this site <%= pageCount %> times.</p>
</center>
<br/><br/>
<br/><br/>
<center>
<p>Copyright © 2015</p>
</center>
</body>
</html>
Output:
An example of Include Directive
You have visited this site 1 times.
Thank you for visiting this page
Copyright © 2015
5.8 Summary
In this whole unit we have learned about jsp and how to create web pages using jsp and different
concepts related to use of jsp for different purposes. We have gone through jsp overview its
syntax and tags and how to use it for rendering different contents we have also learned about
arrays and how to define call and use them. The chapter also illustrates differences between
object and arrays and how they are instantiated. At last a brief explanation of the page directives
and include directives have been provided.