Sei sulla pagina 1di 167

India’s Mega Online Education Hub for Class 9-12 Students,

Engineers, Managers, Lawyers and Doctors.


Free Resources for Free Resources for Free Resources for Free Resources for Free Resources for
Class 9-12 Students Engineering Students MBA/BBA Students LLB/LLM Students MBBS/BDS Students

• Lecture Notes • Lecture Notes • Lecture Notes • Lecture Notes • Lecture Notes

• Project Reports • Project Reports • Project Reports • Project Reports • Project Reports

• Solved Papers • Solved Papers • Solved Papers • Solved Papers • Solved Papers

View More » View More » View More » View More » View More »

▼▼ Scroll Down to View your Downloaded File! ▼▼


Disclaimer

Please note none of the content or study material in this document or content in this file is prepared or
owned by Studynama.com. This content is shared by our student partners and we do not hold any
copyright on this content.

Please let us know if the content in this file infringes any of your copyright by writing to us at:
info@studynama.com and we will take appropriate action.
1

UNIT – 01
Internetworking concepts
Unit-01/Lecture-01
History of the internet
Now as the definitions goes and internet can be defined as the network which is formed by
the co-operative interconnection of a large number of computer networks. Now since
internet is formed by the interconnection of a number of computer networks, sometimes it
is also known as a network of networks. Now here there are a few interesting things that
work with internet. The first and foremost is that there is no single owner of the internet.
Now just unlike a network that you can see in your organization, may be your
m
organization owns the network. In contrast internet, you cannot identify a single
o
.c
owner who owns or who administrates or manages the whole network. Suppose you are
a member of the internet group which means you are computer is also connected to the

a
internet may be it is so as simple dial up telephone line from your residence. Now in that

m
case you are also a part of the internet.

a
Every person who makes a connection to the internet becomes a part of the owner.

n
So I repeat there is no central administration or central authority to the internet. Now

y
just talking about the way internet has emerged as a network of network. If you look

d
into the history of computer networks you will find that computer networks initially

u
started in the later 60s. They were mainly some clusters of some computers in different

t
laboratories and an organization for the main purpose was to connect several computers

S
together. So as to achieve a number of goals like exchanging messages, sharing some
information, etcetera. Now the networks that were at that time they share some
characteristics like they were all proprietary in nature. The network that was there which
was connecting a number of computers. All the computers were of the same type or they
were for the same vendor. For example we could have had a network which comprised of
only IBM computers; a network with only deck computers and so on.
Now with the passage of time people felt, that will these kinds of small networks have
emerged in the different labtories and organizations like small islands. As the requirement
2

or need of the people grew with time, they felt the necessity to connect these networks
together. So that a user of network A can communicator with a user of network B. There
should be a way of communicating between them. But of course in order to that one big
problem needed to be solved, that was the problem of compatibility. I told earlier that
initially the networks are mostly proprietary. A network of say that had connected a number
of IBM computers was totally unknown entity to a HP computer. The HP computer did not
understand how the IBM network would work. So there has to be a common binding force
or a common standard that would all the computers across these networks to talk or
communicated themselves. So this was one of the motivations.

m
o
.c
a
m
a
Now talking about a network of networks internet looks something like this. We have a

n
number of such networks which are connected in some way. Of course picture may not look

y
like this. The diagram as I have shown it is a pure star network. But in practice this does not

d
certainly look like this. The purpose of this diagram is to give you a logical picture of the

u
internet. There are a number of different networks which are all connected through some

t
basic back bone network. The central place this portion this is the central back bone

S
network which connects all the networks together.
So the internet, what is it actually in practice? Well internet is not just the network; internet
is not just the programs or the applications that the users of the internet use. Internet is not
just some document or some resources which are available on some computer in the
network. But rather it comprises of a number of different things. Firstly it is a community of
people who use and develop the network. So people are also part of the internet. So
without people internet would not have existed. Internet also consists of a collection of
Studynama.com - #1 destination for free notes, eBooks, papers & projects.
Choose your course/study level below and start downloading:

CLASSES 6-10 CLASSES 11-12


 Class 6 CBSE NCERT Notes, Solutions  Class 11 Science & Medical Notes, eBooks
 Class 7 CBSE NCERT Notes, Solutions  Class 12 Science & Medical Notes, eBooks
 Class 8 CBSE NCERT Notes, Solutions  Class 11/12 Science & Medical Projects
 Class 6, 7, 8 CBSE NCERT Projects  Class 11/12 Science & Medical Solved Papers
 Class 9 Notes, eBook CBSE PDF Download  Class 11 Commerce Notes, PDF eBooks
 Class 10 Notes, eBooks CBSE  Class 12 Commerce Notes, PDF eBooks
 Class 9 & 10 Projects, PPTs PDF Free  Class 11 Arts Notes, eBooks Free
 Class 9, 10 Solved Board Papers  Class 12 Arts Notes, eBooks Free

ENGINEERING – BE / BTECH. STUDY MATERIAL


 First Year Engineering Notes, Projects  Aerospace Engineering Notes, Projects
 Computer Sc. Engineering Notes, Projects  Metallurgical Engineering Notes, Projects
 Electronics Engineering Notes, Projects  CSE/IT Engineering Projects, Reports
 Electrical/EEE Engineering Notes, Projects  Electronics Engineering Projects, Reports
 Mechanical Engineering Notes, Projects  Electrical/EE Engineering Projects, Reports
 Civil Engineering Notes, eBooks, Projects  Mechanical Engineering Projects, Reports
 Production Engineering Notes, Projects  Civil Engineering (CE) Projects, Reports
 Chemical Engineering Notes, Projects

BBA / BBM MBA / PGDM


 BBA/BBM CORE Notes, Books, eBooks  MBA Core/General Notes, eBooks, Projects
 BBA/BBM Marketing Notes, Books, eBooks  MBA Marketing Notes, eBooks, Projects
 BBA/BBM Finance Notes, Books, eBooks  MBA Finance Notes, eBooks, Projects, Reports
 BBA/BBM HR Notes, Books, eBooks  MBA HR Notes, eBooks, Projects, Reports
 BBA/BBM Operations Notes, Books, eBooks  MBA Operations Notes, eBooks, Projects
 BBA & BBM Projects, Training Report

SCROLL DOWN TO SEE SUBJECT NOTES


3

resources. This is very important because if this resource were not there possible so many
people’s would not have used the internet. Now by having a connectivity or this network of
networks established, what we have is that these resources can be reached from anywhere
in the internet.
So we have some kind of network and over the network you can reach any resource you
want to from any other place. This is a basic idea and internet also provides a set up to
facilitate the collaboration. Now when I say collaboration, this can be simple messaging
facilities like electronic mail or it can be some more concerted collaborative efforts like
having bulletin board system or somebody can pores some problems or a discussion forum
through which you can start an open discussion on some topic, which of course you want to

m
start a discussion on. So particularly this kind of collaboration is very useful in a number of
o
you can say areas in particular among the members of the research and educational

.c
communities. They find this kind of collaborative facility invaluable.

a
Suppose I have a problem I am unable to solve, if I put it in the discussion forum may be

m
somewhere sitting somewhere else would be able to solve my problem and give me a

a
response of the solution to the problem. And talking about the about common standard

n
that bangs on the network together. There is a standard protocol called TCP and IP. TCP

y
stands for Transmission Control Protocol and IP stands for Internet Protocol. So as the

d
scenario is there today, well any computer or any network if it wants to get connected to

u
the internet the computer or the network must understand the language of TCP IP. So all the

t
message exchanges that go on in internet they use the syntax and the format of the TCP IP

S
message packets. So if your computer understands TCP IP then your computer possible can
become a part of the internet if you just have connectivity to it.

The evaluation of the internet


It started as early as in the 1950s where the US defence organization ARPA, it stands for
Advanced Research Projects Agency. This started to network a number of computers that
are funded by the in a very small way. So a few computers which are located in different
paths of the country where provided with some sort of connectivity. So that they can
Studynama.com - #1 destination for free notes, eBooks, papers & projects.
Choose your course/study level below and start downloading:

LLB / LAW MEDICAL


 LLB Notes, eBooks FREE PDF Download  MBBS Notes, eBook, Project, Papers & Cases
 LLB Law First Year PDF Notes, Projects, Papers  BDS Notes, eBook, Project, Papers & Cases
 LLB Law 2nd Year PDF Notes, Projects, Papers  BHMS Notes, eBook, Project, Papers & Cases
 LLB Law 3rd Year PDF Notes, Projects, Papers  BPharma Notes, Projects, Papers & Cases

B.COM ENGINEERING / GATE ENTRANCE


 B.Com. General Notes, eBooks PDF Download  IIT-JEE Mains 2019 Solved Papers, Notes, Cutoffs
 B.Com. Honours (Hons.) Notes, eBooks  IITJEE Advanced 2019: Solved Papers, Notes
 B.Com. Finance Notes, eBooks PDF Download  BITSAT 2019 - Solved Papers, Notes, Cutoffs
 B.Com. Human Resources Notes, eBooks PDF  VITEEE/SRMEEE/MU-OET 2019: Papers, Notes
 B.Com. IT Notes, eBooks PDF Download  UPTU/AKTU 2019 - Solved Papers, Notes, Cutoffs
 B.Com. Accounting & Taxation Notes, eBooks  WBJEE 2019 - Solved Papers, Notes, Cutoffs
 B.Com. Marketing Notes, eBooks PDF Download  MH-CET 2019: Solved Papers, Notes, Cutoffs
 B.Com. BFSI Notes, eBooks PDF Download  EAMCET, COMEDK 2019: Solved Papers, Notes

BCA / MCA / B.SC. MEDICAL ENTRANCE


 BCA Notes, eBooks Download  AIIMS Medical 2019 - Solved Papers, Notes
 BCA Project Reports & PPTs  NEET (AIPMT) 2019: Solved Papers, Notes
 MCA Notes, eBooks Download  AIPVT Medical 2019: Solved Papers, Notes
 B.Sc. Notes, eBooks Download  AFMC Medical 2019: Solved Papers, Notes
 B.Sc.(IT) Notes, eBooks, Papers, Projects  BHU-PMT, CMC Vellore 2019: Papers, Notes

GATE – ENTRANCE FOR MTECH & PSU


 GATE CSE/IT engineering Notes & Papers  GATE Electronics engineering Notes & Papers
 GATE Mechanical engineering Notes & Papers  GATE Civil Engg. Free PDF Notes & papers

SCROLL DOWN TO SEE SUBJECT NOTES


4

communicate among themselves, now subsequently while it continued for some time like
this in 1970s and beyond this ARPA. ARPA became to know as ARPA network advanced
research project agency network. So ARPANET started to create a standard which is basically
the predecessor to the TCP standard that we have today. So at that time the standard that
was proposed that is not exactly TCP, but it is step in the right direction.
So it was a premiliminary protocol which through subsequent you can say refinents and
modification became finally the TCP as we see today. In 1971 the universities were added to
the network, the main purpose was that many of the defense funded research used to take
place in the universities and ARPANET felt universities should be part of the network. And
some basic internet services like telnet and FTP were made available. Now these you will be

m
studying later in more detail. Now using telnet you can start remote session on a different
o
computer sitting on your own computer. And using FTP File Transfer Protocol. You can

.c
transfer a file or a group of files between two machines. These were the basic facilities

a
which were provided at that time for communicating between machines. In 1972 the first

m
version of electronic mail came into you can say being coming to be first email message was

a
sent during that time.

n
In 73, ARPANET spread its reach beyond US it connected to some sites or locations in

y
England or Norway. So it is in 1973 ARPANET started to spread across continents. 1974 TCP

d
was recognized as the standard and it was used for communication across a system of

u
networks. So you can say that in 1974 people actually started to talk about having a number

t
of networks. They all will be speaking the same language and TCP was the vehicle which was

S
used to do or achieve this. Now 1982, the US department of defense it started building their
own defense data network based on the same technology that were developed in ARPANET.
See this ARPANET as it has evolved it also brought along with it a number of different
technologies, some protocols, some standards which people used and were actually able to
communicate. So the US department of defense saw that here we have a technology which
we can use to greet benefit for our case of application also though so they simply borrowed
the technology for their own application and they stated using it. In 1983 this ARPANET
actually got spit into ARPANET and there was a new network military network MILNET
5

which is created which of course had some additional security requirements. That is why
they got split into two.
In 83 we saw the internet which is very familiar to the internet we see today. So in 1983 the
internet started to actually take shape as we see it. TCP IP was recognized as a standard.
Then in 1986 National Science Foundation this stated another network NFSNET. Now
NFSNET, the objective was very simple. The objective was to create very strong back bone
network used to connect the regional networks. As you can see here this NFSNET is a system
of regional networks which were connected over a back bone network. So here there are
some networking devices called routers which were used. And routers belonging to the
different regional networks were strongly connected among themselves and this constituted

m
what is called a back bone network. And the main purpose of NFSNET was to create a very
o
powerful back bone network which would provide these. So called back bone for future

.c
generation communication systems. In 1991 some new applications like Archie and gopher
were released.
a
m
Well many of you may not have heard about these application action gophers. See at that

a
time applications like the ftp file transfer protocol become very popular. People stated to

n
keep a large number of resources on the different ftp servers and through ftp you can

y
basically connect to that server and you can download the material whatever you want. It is

d
very similar to the World Wide Web that we see today, I am sure most of you have used the

u
internet through the World Wide Web through the browser and you know how it looks like.

t
But at that time there was no user interface just we have to give command get a file and

S
after you bring the file to a machine you can open it and see what it is. Now the main
problem that people used to face that time is suppose I want some resources, say I want a
particular document on a subject. So how do I know where that subject or that document is
located? While if I know the address at that time some big ftp catalogs were published, I can
look at the catalog and find out where these documents are located in this ftp server.
So let me connect there and see if I can find it out. So this Archive was developed as an ftp
search engine. Well many of you are familiar with Google, Yahoo; the search engines which
people today. So at that time Archie was the search engine through which given a topic you
6

want to search for. Archie return a list of ftp sites where you could possible get that topic.
And gopher was you can say a more intelligent version of Archie gopher showed you the
documents in a category and sub category few it was like a global view, you can browse
through categories and subcategories suppose flower rose, black rose. If you click on black
rose you can get a list of place you can get information about black rose. So this gopher
allowed you to browse ftp sites through well defined you can say category and subcategory
view. Well gopher was a little more general it covered the ftp sites as well as some other
non ftp sites also. But I am not going into those details right now.
Well 1992 the internet linked more than 17000 networks; there were about 3 million hosts.
1993 the World Wide Web application were launched. Today you know this World Wide

m
Web is a defector standard anyone owning a computer. They use World Wide Web; they use
o
either the internet explorer or Mozilla conqueror. Some kind of browser they use to access

.c
the World Wide Web 1995, the concept of networks service providers came into be and this

a
network service providers start to offer service. But earlier you had to build your own

m
network and it was your responsibility to get your network connected to the internet back

a
bone. Now there are service providers, well in India there are service providers like VSNL,

n
like Satyam, like Reliance, there are so many today. Now you can approach them. They will

y
provide you a connection and it would be there responsibility to get your network

d
connected to the internet back bone. So in 1995 you can understand you have about 30

u
million users. So the growth was fantastic. Growth of Internet

t
S

So this simple file shows you the exponential nature of growth that internet enjoys. You see
in 1989, from about 10 million hosts, in 2001 you have 100 million hosts. So over a period of
time, the numbers of nodes have increased in a fantastic way. So this exponential growth
7

continues and as of today we have more than a billion hosts which are connected in the
internet.
Now as the internet came in place and it became popular with the passage of time, there
were a number of internet applications that were developed. Some were accepted widely,
some they were not accepted and finally they got rejected. But here listing a few of the
internet application which became popular, in fact are still very popular, in fact all of them.
The first one TELNET. I told you about this TELNET; allow a user to log into a remote
computer and start so called remote session. That means I am sitting on my computer, I am
running a program, and I am viewing the file. But actually everything is happening on the
other computer. What I am seeing on my screen is the output of that program is coming

m
straight away to my screen and I am having an illusion that I am actually sitting on that other
computer; not on my computer. o
.c
Similarly you can have file transfer protocol. This I have, this also I have mentioned using

a
this, you can transfer file between machines. Then you have the so called electronic mail. In

m
fact today email is the single largest application which is used by people. While every person

a
who gets connected to the internet invariable uses email. This email has become you can

n
say part and partsell of daily life and is very fast making the so called surface mail which

y
somebody also calls snail. In comparison with the speed so the surface mail is becoming

d
obsolete and redundant in many cases. Many of us today prefer to send documents and

u
reports by email rather than by surface mail. Gopher I have mentioned gopher although

t
today you do not see many gopher application. But there was a time in 80s and mid 90s

S
where gopher was very popular.
It was you cannot say just a previous version of the internet as we see today. So through
gopher you could browse through categories and sub categories, you can access the
document or the resource you want to access and you can use it in a convenient way. This
internet relay chat is another application which is also very widely used by people. Through
this internet relay chat you have you can say a medium through which a number of persons
can communicate among themselves. Well if I type in some message, that message can be
viewed by all members of the group with whom I am participating in that chat. So this chat
8

is a very useful tool and if used in the proper context can prove itself to be extremely useful
and beneficial, particularly in education. This Usenet news this is also very important
application news. Well broadly this is like a discussion group news group or a discussion
forum, say I have a discussion forum through I can start a discussion.
I can float a topic, the other members of the community who are also there in the forum
can post, their reviews I can see them while I mentioned. If I have a problem I post the
problem on the discussion forum and someone else may be coming up with a solution and
posting it there. While the advantage is that I may be having my personal problem which I
have posed and someone else has posted a solution to this. But there may be a number of
other people who are having similar problem. So if they look through the mails that are

m
getting exchanged through the discussion forum, they can possible also find a solution to
o
their problem automatically by just following the discussion that is going on. And of course

.c
lastly the World Wide Web which is the most important application that we are today. In

a
fact today World Wide Web can we treat it in as an umbrella and under the umbrella all

m
other protocols can be used like electronic mail, like ftp, like news groups.

a
Everything else can be accessed under the same umbrella of World Wide Web. So World

n
Wide Web will itself is an application and it also integrates other application together. So

y
today we have a single common interface, we start a browser and through a browser we can

d
have basically access everything. Now let us talk about something else. See this internet has

u
evolved over a period of time. There are new protocols which have come up many of them

t
have become so popular. Now suppose a new protocol comes up lets take an example say

S
the email; electronic mail. Now you know today all the machines, all the computers, all the
operating systems they support electronic mail and somehow they are compatible. If I send
a mail from one computer to the other which reaches the destination so you can guess
there has to be some kind of a standardization effort that goes on somewhere.
Internetworking concepts
Internetworking is a scheme for interconnecting multiple networks of dissimilar
technologies
 Uses both hardware and software
9

 Extra hardware positioned between networks


 Software on each attached computer
 System of interconnected networks is called an internetwork or an internet
Routers
 A router is a hardware component used to interconnect networks
 A router has interfaces on multiple networks

 m
o
Networks can use different technologies

.c
 Router forwards packets between networks
 Transforms packets as necessary to meet standards for each network
Internet architecture a

m
An internetwork is composed of arbitrarily many networks interconnected by routers

a
n
y
d

u
Routers can have more than two interfaces

t
S

Routers in an organization
 Would be possible to interconnect all networks in an organization with a single
router
10

 Most organizations use multiple routers


 Each router has finite capacity; single router would have to handle all
traffic across entire organization
 Because internetworking technology can automatically route around
failed components, using multiple routers increases reliability
A virtual network
 Internetworking software builds a single, seamless virtual network out of multiple
physical networks
 Universal addressing scheme
 Universal service
 m
All details of physical networks hidden from users and application programs
o
.c
a
m
a
n
y
d
u
t
S

A protocol suite for internetworking


 The TCP/IP Internet Protocols or, simply, TCP/IP is the mostly widely used
internetworking protocol suite
 First internetworking protocol suite
11

 Internet concept (originally called catenet developed in conjunction with TCP/IP


 Initially funded through ARPA
 Picked up by NSF
Internetworking protocols
 Others include IPX, VINES, AppleTalk
 TCP/IP is by far the most widely used
 Vendor and platform independent
 Used in the Internet - 20 million computers in 82 countries
TCP/IP layering

m
OSI 7-layer model does not include internetworking

o
 TCP/IP layering model includes five layers

.c
a
m
a
n
y
d
Layer 5: Application u
t
Corresponds to ISO model layers 6 and 7; used for communication among applications
S
Layer 4: Transport
Corresponds to layer 4 in the ISO model; provides reliable delivery of data
Layer 3: Internet
Defines uniform format of packets forwarded across networks of different technologies and
rules for forwarding packets in routers
Layer 2: Network
Corresponds to layer 2 in the ISO model; defines formats for carrying packets in hardware
12

frames
Layer 1: Hardware
Corresponds to layer 1 in the ISO model; defines basic networking hardware

Hosts, routers and protocol layers


 A host computer or host is any system attached to an internet that runs applications
 Hosts may be supercomputers or toasters
 TCP/IP allows any pair of hosts on an internet communicate directly
 Both hosts and routers have TCP/IP stacks
 Hosts typically have one interface and don't forward packets
 Routers don't need layers 4 and 5 for packet forwarding m
o
.c
a
m
a
n
y
d
u
t
S
13

Unit-01/Lecture-02
TCP IP
TCP IP is a protocol which well you can say it stated as early as in 1970s and it got very
quickly accepted by a white community of users. In fact when the internet came into the
being, TCP IP was the prime vehicle which was used to connect the computers in the
internet and to allow them to communicate over the network. Using TCP IP the computers
were able to communicate among each other. And also another very important thing, they
were able to share some resources across the network. Some of the resources like dig space
or some of the some of the expensive equipments were expensive in those days and over

m
the network it was possible to share those resources. And work on TCP IP stated in the late

o
60s and in the early 70s it started to take shape. Now in US like most of the innovative

.c
developments, the initial research on TCP was funded by the US department of defense the
military. So as part of their project it started with a very small network it was called ARPA. It

a
was called advanced research project agency ARPA and the network which evolved in the

m
process it slowly came to know as the ARPANET or the ARPA NETWORK. So this ARPANET

a
was the first network you can say which started to use the first version of TCP.

n
Now this TCP has become so widely accepted technology in modern internet that you can

y
say that in today’s world the internet as we see, this is entirely dependent or based on the

d
TCP IP technology which lies under it. So in the internet TCP IP today is treated as a

u
standard. Standard means say when you buy or purchase a new computer and if you want it

t
to get connected to internet the first thing you must ensure that your computer learns or

S
understands the language of TCP IP. Because this is important because all other computers
which are connected to the internet. They know and understand TCP IP. So if your computer
can talk in the same language then you can communicate with the others. But suppose you
have a computer which has a proprietary system, it uses something other than TCP.
Then it will not be possible for your computer to send a message or communicate with
some other computer which is connected to the internet somewhere else. So this TCP IP is a
standard it has been used to bridge the gap between non compatible platforms. Well you
say non compatible platforms, what I mean to say is that some of the machines you are
14

trying to connect may be running the windows operating systems. Some may be running
some version of UNIX, Linux; some may be Macintosh machines, macs. So there are wide
varieties of types of machines and operating systems which are in the use today. So if all of
them have a common layer of software namely the TCP IP then using that common layer
they can very easily talk among themselves and work in you can say synchronizing with each
other. So the most important point you notice that all computers connected to internet
today must understand TCP IP, this is important
purpose of layering
Well we develop software in terms of layers. Because number one is that if we make some
change in one of the layers as long as the interfaces remain the same, the other layers need

m
not be modified. So if the interface remains the same we can make changes to a layer pretty
o
easily. This is of course one reason; the second reason is that if we have well defined layers

.c
your total software can be defined into well-defined modules. So the software development
process also becomes much easier.
a
m
OSI 7 layer model

a
n
y
d
u
t
S
Now just to recall the OSI 7 layer model, had these 7 layers starting from the lowest level
physical, data link, network, transport, session, presentation and application. Now you recall
one thing. Suppose you have a network like this, there are several nodes connected. Right
these are several networks nodes connected and there are some links which are joining
15

them. Suppose this is my source and this is my destination. I want to send some message
from the source to this destination from the source to this destination. Now there are some
of the layers, in fact the lower 3 layers physical, data link and network. They work on a point-
to-point link means they work or they cooperate in sending the data over this link, over this
link and so on.
Whereas the higher 4 layers for them the intermediate thing is more like a black box. Only
the 2 end systems are important and whatever this source is sending as if the destination is
receiving directly. This is the advantage you have in layering the lower 3 layers of the
software. These are working on the point -to-point to links. But they ensure that the packets
which are starting from S will finally reach D. In contrast the higher 4 layers, they are not

m
worried about how the packets are delivered to D. They are more worried about what is
o
reaching D. Finally these are therefore called host-to-host layers because for them the

.c
internal network is a black box. Only the two communicating entities are the 2 ends the

a
source and the destination. They are important as if the source is directly talking to the

m
destination.

a
TCP IP the simplified 4 layered model

n
y
d
u
t
S

TCP IP the simplified 4 layered model which is used, well if you draw an analogy from the
OSI model approximately the layering would look like this. At the lowest level this is
sometimes called the data link layer. This layer will be responsible for the transmission of
frames over link. But one thing you understand all thought the lower level link is called the
16

data link layer. This must also include the physical layer. Now the reason they are put
together in a single block or layer is that in most of the modern systems what happens is
that we have also called network interface card or a nic which we put inside your computer
and through a networking cable we connect that nic. Now that nic that piece of hardware it
works both as a physical layer and as the data link layer. So both the two layers get
embedded into the hardware interface card. That is why we really cannot distinguish the
two layers in modern day systems.
That is why they are often embedded into a single layer. Now the next higher layer the
network layer. This is responsible for packet delivery across the internet or source sends a
packet. It is the network layer in all the intermediate nodes as well as the source and

m
destination. It will be responsible for routing or forwarding the packet systematically from
o
the source to destination along the correct path transport layer is the end-to-end link where

.c
the source and destination can talk directly and application is any program which can run on

a
top of these. Now examples of applications may be electronic mail. Email may be any other

m
program you are running which is communicating with any other client server programming,

a
in fact which is communicating with another program on the other machine. They can be

n
treated as application.

y
Dataflow in 4 layer model

d
u
t
S

Now in a 4 layer model, let us look into this diagram in a slightly more detail. Now what we
are showing here is that there are 3 nodes A, B and C. Suppose A is the source, C is the
17

destination and the packets are the data from A, go to C via an intermediate node B. So
when I say that A is the source and C is the destination I mean is that on machine A, there is
some application program which is running. Similarly on machine C there is some other
application which is running which will be receiving the data send by the application running
on A. So what the application program running on machine A will do is that, it will send
some information down to the transport layer. Transport layer will be sending it down to the
network layer.
Network layer will take some decision that will it will be looking at the destination address.
The address where the packet has to be delivered and in case this node A has more than
one outgoing links. It will take the decision through which outgoing link the packet has to be

m
forwarded. So the network layer will be sending back the information to the data link layer
o
corresponding to this selected link. For example I have selected this link, so over this

.c
physical link the data packets or the frames will go to machine B. Machine B is not the final

a
destination. Now here again there can be several outgoing links. So what this machine B will

m
do, it will again send back the packet to its network layer. And the network layer will again

a
take a decision depending upon the destination address that over which link we have to

n
forward it.

y
Suppose it selects this link, so now from the network layer it again comes down to the

d
datalink of that corresponding selective link. So finally the packet reaches C. So from C again

u
it traces the reverse route datalink to network network to transport and transport back to

t
the application. So the point to note is that in all the intermediate nodes only the networks

S
layers up to the network layer, datalink and network these two layers are coming into the
picture. One is at the two ends where the end to end layers like transport and application
are being used. So this diagram shows that how typically data flows in a four layer model
network model. So now let us come to TCP IP specifically what the TCP IP suite of protocols
really mean?
Now as I had mentioned TCP IP does not refer to a single protocol or a few two or three
protocols. In fact this refers to a family of protocols. All these protocols are built on top of a
so called connection less technology. Now connectionless technology as you had seen
Studynama’s BDS Community is one of India’s Largest Community of Dental Students. About
19,232 Indian Dental Course students are members of this community and share FREE study
material, cases, projects, exam papers etc. to enable each other to do well in their semester exams.

Links to Popular Study Material for BDS (Dental) students:


 Orthodontic Fixed Appliances - BDS Lecture Notes PDF Download
 Amalgam Restoration - BDS Lecture Notes PDF Download
 COMPLEX NON-SKELETAL PROBLEMS IN PREADOLESCENT CHILDREN - BDS Lecture Notes
 Anatomy of Scalp - BDS Lecture Notes PDF Download
 Cerebrospinal Fluid (CSF) - BDS Lecture Notes PDF Download
 Cementum - BDS Lecture Notes PDF Download
 Recent Advances in Instrumentation Techniques - BDS Lecture Notes PDF Download
 Ameloblastoma - BDS Lecture Notes PDF Download
 Prevention of Odontogenic Infection - Principles of Management - BDS Lecture Notes
 Therapeutic Dentistry Histology of Teeth Dental Charting - BDS Lecture Notes PDF Download
 Maxillofacial Trauma and Management - BDS Lecture Notes PDF
 Technical Endodontics - BDS Lecture Notes PDF Download
And 698 more free downloads for Dental Students.
Other Popular Links for Law Study Material:
 BDS Lecture Notes, eBooks, Guides, Projects and Case Papers FREE PDF Download
 BDS Lecture Notes, eBooks, Guides & Handouts FREE PDF Download
 BDS University Previous Year Exam Question Papers & Solutions FREE PDF Download
18

earlier, these means datagrams. There is a basic mechanism of transporting datagrams over
the network. So in TCP IP the basic idea is that data will be sent from one node to the next
as a sequence of datagrams. Now exactly the way datagrams work each datagram is
independent of the others. So the datagrams will be sent independently. Now again it is a
characteristic of datagrams. Since they are send independently there is no guarantee that
the datagrams that comprise of the same message will be following the same path. Say
suppose I have a message I break up the message into 5 datagrams and I send them
independently, each of these 5 datagrams may be following different paths. So there may be
reaching the destination following different paths. And accordingly the order of arrival may
be different. Some of the datagram may get lost in transit and if there is some error

m
checking time out retransmission then some duplicate datagrams may also get generated.
So variable delay arrival order at destination are possible. o
TCP IP family Members
.c
a
m
a
n
y
d
u
t
S
Now let us have a very quick look at the important members of the TCP IP family. This
diagram summarizes the different important family members in TCP IP. Of course at the
lower level we have the data link and the hardware layers this refers to the network
interface card as I told you. Typically we use Ethernet at this level at the next higher level,
this is the network layer level in TCP IP the protocols that works at the network layer level is
called internet protocol or in short IP. So IP is the main protocol which is working at the
network layer level. But in addition there are several auxiliary protocols like internet control
19

message protocol, group message protocol, address resolution protocol and reverse address
resolution protocol which also works at the network layer level.
But they have specific functions like ICMP is used to generate and send some error
messages, like for example address resolution protocol is used to translate from an IP
address into an Ethernet address. For example, so IGMP and RARP also have some specific
purposes. But in a typical application you will be using internet protocols. These protocols
are typically hidden from the applications. These are invoked and used in a transparent way.
As a user you will not be able to see that they are been used or as a programmer also. You
will not be using them directly. Now at the transport layer level you have two options. You
can either use transmission control protocol or TCP or you can use user datagram protocol

m
or UDP. So you see although we call it TCP IP actually you can also use UDP and IP. TCP IP is
o
just a name for this family moving up to the application layer level.

.c
So at the application layer level there are a number of well-defined applications. Only a few

a
of them I have listed here we have file transfer protocol, we have trivial file transfer

m
protocol, we have simple mail transfer protocol, we have simple network management

a
protocol, domain name server or you can have any general user application which has been

n
developed. This is only a short listing, general you can have any number of applications at

y
this level. So typically an application running on this level. For example this user process.

d
This can interact with either TCP or UDP depending on what you want. TCP or UDP in turn

u
will interact with IP then IP will interact with the lowest layer. This diagram shows that

t
simplified typical data flow model.

S
Studynama’s Engineering Community is one of India’s Largest Community of BE & BTECH Students. About 79,182
Indian Engineering students are members of this community and share FREE study material, notes, eBooks, major
and minor projects, exam papers etc. to enable each other to do well in their semester exams.

Links to Popular Study Material for Engineering (BE/BTech) students:


CSE & IT Engineering Electronics Engineering Electrical Engineering Mechanical Engineering Civil Engineering

Computer Science Electronics Engineering BTech Civil/Structural


Electrical/EE Engineering Mechanical/Automobile/IP
(CSE/IT Engineering) (ECE/ET/EC) Engineering Second
Second/2nd Year Notes Engineering second year notes
Second/2nd Year Notes Second/2nd Year Notes Year Lecture Notes

CSE/IT Computer Electronics Engineering BTech Civil/Structural


Electrical/EE Engineering Mechanical/Automobile/IP
Science Engg. Final/4th (ECE/EC/ET) Third/3rd Engineering Fourth
Third/3rd Year notes Engineering fourth year notes
Year Notes Year Notes Year Lecture Notes

Computer Science Electronics (ECE/ET/EC) BTech Civil/Structural


Electrical/EE Engineering Mechanical/Automobile/IP
Engineering (CSE/IT) Engineering Final/Fourth Engineering Third Year
Fourth/4th Year Notes Engineering third year notes
Third/3rd Year Notes Year Notes Lecture Notes

Advanced Java Antenna & wave Electrical Machine-1 pdf Automobile engineering lecture
Surveying 1 - eBook
Programming eBook propagation eBook download notes

Web Technology - Network analysis & Electrical machines-II Engineering materials & SOM - strength of
eBook synthesis notes eBook metallurgy lecture notes materials - eBook

E-Commerce lecture VLSI engineering pdf Manufacturing Technology-1 Engineering Geology


EMI eBook
notes lecture notes lecture notes eBook

And 12998 more free downloads for BE & BTech Students.

Other Popular Links for Engineering Study Material:


• Engineering First Semester (Sem 1) Notes
• Engineering Second Semester (Sem 2) Notes
• Engineering chemistry pdf eBook
• Engineering Mechanics PDF Lecture Notes
• Electrical/EE Engineering notes
• Mechanical/Automobile/IP Engineering notes
• Powerplant Engineering Lecture Notes
• Engineering Mechanics lecture notes
20

This is the typical scenario for at the application layer level the user process they will be
using either TCP or UDP. There is a choice, there is a characteristic, they will be in turn using
IP and IP will be interacting with the lowest layer. So the most important members of TCP IP
family are TCP, UDP and IP; these three. So first let us try to say briefly what the basic
functionalities of three models are? First let us look at IP the protocols that works at the
network layer level has. I had mentioned that a network layer protocol is responsible for the
correct routing of a packet from the source to the destination. So it will take some decision
that where to forward or send the packet next and the packet will find its way from the
source to the destination taking help of the IP layer. IP layer software that is running on each
of the intermediate nodes
What does IP do? m
o
Basically IP is a transport system for datagrams. So at the level of IP it is only datagrams

.c
which flow on the network. So IP is basically a datagram packet delivery system. It is

a
responsible for routing the packets. Of course moreover if it sees that a packet is too large it

m
cannot be handled by a network, then it can break a packet into smaller pieces which are

a
called fragments which will be talking about later. That how it is done? So a packet may be

n
broken into smaller fragments of packets which later will need to be reassembled again to

y
get back the original packet. Now this reassembling is done at the final destination. But the

d
point to notice that IP does not do any kind of error control. It is an unreliable service, it is

u
basically a datagram service and all the unreliability that comes with datagram it stays with

t
IP also like a packet may get lost.

S
Packet may get arriving, may arrive out of order because the individual packets may follow
different paths to the network. And in case of time out and retransmission duplicate copies
of the same packet may be flowing through the network. So the final destination the IP layer
at the final destination has to manage all these things packets arriving out of order. Some
packets not coming at all and multiple copies of the same packet coming. So these issues
have to be handled there. Now looking at TCP which works at the transport layer level and
you recall the transport layer level is an end to end protocol where the two hosts which are
running on the two machines they talk to each other.
21

What does TCP do?


TCP is a reliable transport layer protocol, well when you say reliable. What do you mean is
that it is connection oriented reliable service. When you say connection oriented, well the
user or the user application gets an illusion that there is a connection which has been
established between the two end systems. So the application program running on one
computer believes that a connection as been established with the application running on
other end system. And I can send some message directly to the other machine. But what
happens in practice is that ultimately the data will be transported by the IP layer below.
When IP is an unreliable layer. So TCP has to do some additional error checking and in case
of error TCP will have to recover from the error. So TCP will be given illusion to the layers

m
above it that well everything below you is a very reliable network. So essentially the tasks
o
which are performed by TCP is that splitting a message into packets, reassembling the

.c
packets at the destination again and it checks if some of the packets are missing.

a
So if there are missing and explicit request is sent back to resend that packets and in this

m
way reliability is ensured. And TCP sits on top of IP so the way it interfaces is that the

a
packets which TCP generates will be forwarded to IP individually for delivery. But IP does not

n
do any error checking or error control. So all error control is the responsibility of TCP. So this

y
is a nutshell is what the TCP layer is supposed to do and the user datagram protocol called

d
UDP. That is also a transport level protocol, but that is different. Well as compared to TCP,

u
TCP tries to provide reliability it tries to establish provide a connection oriented service. But

t
UDP does not try to anything UDP says that well I am trying to transport a packet as fast I

S
can, I am not concerned about reliability. I am not concerned about in which order the
packets are going. I will try to impose a minimum amount overhead. I will try to deliver the
packet fast this is the philosophy behind UDP.
What does UDP do?
So UDP provides a connectionless service like there is no apparent connection that is set up
between the source and the destination. This is an unreliable service because it does not do
any explicit error checking or error control. The applications which prefer to use UDP are
those for which messages are small enough which can be fit into a single packet. A typical
Studynama’s Law Community is one of India’s Largest Community of Law Students. About
29,982 Indian Law students are members of this community and share FREE study material,
cases, projects, exam papers etc. to enable each other to do well in their semester exams.

Links to Popular Study Material for LAW (LLB & BA.LLB) students:
• Family law pdf lecture notes & eBook download for LLB students
• Jurisprudence Law lecture notes pdf & eBook download for LLB students
• Company Law lecture notes pdf & eBook download for LLB students
• Law of Evidence lecture notes pdf & eBook download for LLB students
• Contract Law lecture notes pdf & eBook download for LLB students
• Criminal law pdf lecture notes & eBook download for LLB students
• Taxation Law lecture notes pdf & eBook download for LLB students
• Law of torts pdf eBook & lecture notes for LLB students
• Constitutional law pdf lecture notes & eBook download
• Labour law lecture notes pdf & eBook download for LLB students
• Administrative law lecture notes pdf & eBook download for LLB students
• Constitutional Law - I q&a notes pdf & eBook download for LLB
And 1998 more free downloads for Law & LLB Students.

Other Popular Links for Law Study Material:


• LLB/LLM Lecture Notes, eBooks, Guides, Handouts FREE PDF Download
• LLB - Law third year notes, eBooks, handouts and study material - semester 5 & 6
• LLB - Law second year notes, eBooks, handouts and study material - semester 3 & 4
• LLB - Law first year notes, eBooks, handouts and study material - semester 1 & 2
22

example is the query that is sent out by the domain name system. DNS query is an example
of such a message. In fact DNS uses UDP for that purpose because the protocol is much
simpler. You do not have to establish a connection, do not have to maintain a history of the
packet so that if a packet gets lost you cannot send back a request for retransmission.
So since you are not doing all these book keepings, this protocol is much simpler in
comparison. This is simpler as well as faster as compared to TCP. So since it is simpler it will
never split a data into multiple packets. It is expecting that the packet will be of a size which
can fit into a single datagram and it does not care at all about error control interface with IP
is very simple each UDP packet is a datagram it is simply forwards to IP for delivery. So
interface with IP is also very simple here. Now there is another issue.
Addresses in TCP/IP m
o
.c
a
m
a
n
y
d
u
Well if you have another look at this TCP IP stack. Just showing the important protocols TCP,

t
UDP and IP broadly there are three layers. If you recall the physical and the data link layer,

S
the network layer and the transport layer. Talking about the addresses in each of these three
layers, there are three different addresses which are used at the lowest layer. Just assuming
the lowest layer is an Ethernet. Here you use something called the physical address of the
interface link. In this case, this will be a so called Ethernet address and this is a 48 bit
address. This 48 bit Ethernet address is embedded inside the network interface card which
you plug into your computer. So it is that card which a hardware address has built into it that
is the Ethernet address. So when a frame finally comes to your computer, it must come with
the Ethernet address as part of the packet or frame.
23

But when you are looking at the network layer it is a 32 bit IP address which is used to
identify the computers in the internet. Now this 32 bit IP address is allocated and assigned
in a much more systematic way. This is a logical address, no computer comes with that
address built in you can program a computer you can assign any IP address to it. Now the
purpose of this assigning of IP address is that you are trying to make it easier for the
intermediate nodes in the network to forward and route packets just by looking at the IP
addresses. But once the packet enters or comes into the LAN where the final destination
node is situated, so there you have to finally find out the Ethernet address of the
destination. That is done through that ARP protocol I talk I talked about a little ago. So using
ARP you get the Ethernet address and finally the packet will reach the final destination
addressed by the 48 bit Ethernet address. m
o
Now at the level of the transport layer, now you recall the transport layer is the end to end

.c
layer. So here two applications on two end hosts are communicating. Well here also there is

a
an address called port address. It is a 16 bit wide address, well let us see why this is required

m
or needed. Now at the transport layer level when there are two end hosts and two

a
applications running there are trying to communicate, it may be very much possible that

n
would each of these machines. There is not only one application but several applications

y
running. That is the typical scenario in most computer systems today. There is time sharing,

d
there is multi-tasking. So there are many programs which are running at the same time. So

u
you must mention that when you are sending a message to exactly to which application

t
program at the other machine you are trying to send the message.

S
So this port number in essence identifies an application which is running on the particular
machine. This is why we have hierarchy of addresses. Physical address to ultimately identify
the machine through its hardware interface card. This IP address in order to identify the
network where the machine belongs and finally to send route the packet to that network
and the port address to identify an application running on the end machine end host. Now
any layering of software just see this networking software all of them have some sort of
layering. We talked about the seven layer OSI model. Now we are talking about the 4 layer
TCP IP model. Now when there is layering the packets flow in the systematic way from top
24

to bottom and again from bottom to top. Now as this information flows up and down some
additional information gets appended or removed during these movements.

m
o
.c
a
m
a
n
y
d
u
t
S
Studynama’s MBA Community is one of India’s Largest Community of MBA & PGDM Students. About 29,882 Indian
Management students are members of this community and share FREE study material, notes, eBooks, projects, case
studies exam papers etc. to enable each other to do well in their semester exams.

Links to Popular Study Material for Management (MBA/PGDM) students:


MBA General MBA Marketing MBA Finance MBA HR MBA Operations

MBA/PGDM first Enterprise resource Security analysis & Business environment MBA Operations
year notes planning (ERP) pdf portfolio Mgmt. Notes Notes

MBA/PGDM second Marketing International Fin. Human resource MIS pdf


year notes management pdf management eBook management pdf

Principles of International Advanced financial Compensation Industrial safety


management pdf marketing eBook management eBook management Notes eBook

Managerial Retail marketing Corporate taxation International human Import export


economics eBook eBook pdf eBook resource management pdf mgmt. lecture notes

Organizational Sales management Financial Human resource TQM eBook


behavior pdf eBook management eBook development eBook

Operation research Brand management Management Organization & Management


lecture notes pdf accounting notes management process pdf control systems

And 12,998 more free downloads for MBA & PGDM Students.

Other Popular Links for MBA Study Material:


• MBA/PGDM Core (General) Notes, eBooks, Projects, Cases & Reports FREE PDF Download
• MBA/PGDM Marketing Notes, eBooks, Projects, Cases & Reports FREE PDF Download
• MBA/PGDM Finance Notes, eBooks, Projects, Cases & Reports FREE PDF Download
• MBA/PGDM HR Notes, eBooks, Projects, Cases & Reports FREE PDF Download
• MBA/PGDM Operations Notes, eBooks, Projects, Cases & Reports FREE PDF Download
25

Unit-01/Lecture-03
Internet address and domains
The problem of basic IP addressing. Well one thing we had seen earlier that the source and
destination address in the IP protocol is a 32 bit quantity that is the IP address.
Now in the internet scenario, now if you want one host to communicate with other they must
all have unique IP address. Because when you are sending a packet with a destination IP
address, you must be sure that there is only one computer in this world who has this
particular address.
If there are more then there will be confusion and the packet may be delivered in the wrong
place. So we have the concept of IP address which is supposed unique with respect to each

m
host. This is a 32 bit quantity and representing a 32 bit quantity has a streams of 0 and 1s is

o
inconvenient. So it is typically expressed as a so called dotted decimal notation.

.c
Dotted decimal notation means there are 4 decimal numbers W. X. Y. Z separated by dots and

a
W. X. Y. Z represent the decimal equivalence of each of the 4 octets or the 8 bit chunks in the
address.

m
Well we have an example I will show you now this IP address logically contains two parts. Well

a
one part identifies the network. Suppose your computer is located inside your organization

n
network. So the first part of your compute address will identify the address of your network.

y
So using that information the packet must reach your network.

d
So there is one part in the address which identifies the network where the destination host

u
belongs. But the other part indicates the host number which means ones the packet reaches

t
the destination host.

S
Then after that you use this host number to identify the computer where this packet has to be
delivered or has to go. Now this division of IP address into two logical parts network number
and host number.
This can be done in a very simple systematic way, we shall see very shortly. There are
something called IP address classes which are defined. We can use this IP address classes for
this kind of logical division
26

Dotted Decimal Notation

m
o
.c
a
Well first let us look at the dotted decimal notation with respect with the example. Suppose I

m
have an IP address, this is a 32 bit quantity like this. This 32 bit address I am dividing out into

a
four 8 bit chunks. These are the 4 octets and each of the 4 chunks I am converting into

n
decimal. This is 66, this is 134, this is 48 and this is 126. So after you convert each of these

y
into decimal I simply write down the decimal numbers separated by dots and this is the so

d
called dotted decimal notation. So we typically express the IP address of the machine in this

u
form 4 numbers separated by dots this so called dotted decimal notation.

t
S
Hierarchical Addressing
So talking we just mentioned that when we want to address the computer which is connected
to the internet we actually specify two things the network number and the host number this
actually represents a hierarchy in terms of the addressing. Now whenever you want to
mention the network number well as I had mentioned the network number is something
unique to your network. So whenever a node or a router sees that the network number of the
destination address is something say x. So it knows where the network x is located and it tries
to throw or forward the packet direction. So somehow the network addresses must be
27

ensured to be unique across the world. So for this purpose there has to be some kind central
authority that grants and manages these network numbers.
So if your organization has a network address no other computer network in the world must
have or can have the same address, this must be ensured. So the network numbers the
assignment and management is done by some central authority. So just whenever when you
want to set up your own network, you can apply to the central authority. They will be granting
you a new network number new unused network number you can use it for your network.
The next part of the address the host number of course this is a local issue. Once the packet
enters your network the way you number or address a host it is up to you. So these are
assigned and managed by the local network administrator. So there is one part of the address
which is managed globally. m
o
There is another part of the address which is managed locally but when you talk about

.c
routing a packet actually we talk about leading a packet to the correct destination network. So

a
in order that the packet reaches the correct destination network we need not look at the

m
whole of the address. We need to look at only the network portion of the address. The host

a
portion of the address will be required only after the packet has reached or arrived at the

n
destination network. So this is one thing which should be kept in mind this is very important

y
that it is only the network portion of the address which is responsible or is used for the

d
purpose of routing the packets. So this is what is mentioned out here.

u
IP Address Classes

t
S
28

Now, in terms of the IP addresses. IP address are divided into several classes as you can here A
B C D E. So out of them you can leave out E. E is really not used, this is a reserved category.
Well if you want to do some experimentation on IP addresses you can use this class E the first
three classes A, B and C. These are so called unicast address unicast means that using these
addresses you are identifying one particular network on the internet. The addresses uniquely
specify one computer. In contrast class D is a multicast address. MULTICAST means you want
to send a packet to a group of computers. Say all computers which are belonging to a LAN you
want to send them all at the same time. So this is something called multicasting. The address
will be such that it will be broadcast or multicast to all the computers within a particular
group. Now which class the IP address belongs to this is identified by the first few bits in the

m
IP address. Now in addition to these classes we shall see that there also exists some special
purpose IP addresses. Now let us see this in some detail. o
.c
Now this class based addressing this class A B C D E as I had mentioned. Here in these

a
addressing schemes there is a fixed and well defined partition of an address with respect to

m
the network part and host part. Network address part and the host address part, this partition

a
is fixed and this mode of addressing a computer based on address classes is also called the so

n
called classful model. Depending upon the network classes as we will see the network to host

y
ratios of the network can vary. Depending on which class we use you can have different

d
network configurations. These we will see very shortly how this is done.

u
Class A address

t
S
29

First let us see the basic characteristic of the different address classes first the class A. Class A
represents those networks which are very large in size particularly the very big internet
service providers. They would like to have a class A kind of address. Let us see what class A
address says. In a class A address first thing is that these are the 4 octets; 1, 2, 3 and 4. A class
A address begins with a number 0, the 7 bits out here represents the network. So other
number of network bits is 7 and host is 24. 24 bits represents the host. In 7 bits although the
total number of combination is 2 to the power 7 or 128 we shall see that out of the one
particular combination is left aside for some other purpose.
So actually the total number of such network addresses you can have in class A will be a one

m
less it is 127. Similarly for the hosts each of these class and networks can have of the order of
o
2 to the 24 hosts. Out of them we will see again that the all 0 and the all one combinations

.c
are used for some other purpose. So actually you have two addresses less it comes to a figure

a
like this 16 above 16 million. So number of hosts in a class and network can be large as 16

m
million based on this address assignment in the dotted decimal notation a class A address can

a
range from 0, 0, 0, 0 up to 127, 255, 255, 255. That means all zeros up to all ones. This is the

n
range, so if you see an IP address within this range you can immediately identify that is a class

y
A address.

d
Class B address

u
t
S

Now class B belongs represents the network which are medium in size; smaller than class A,
but larger than class C we will see later. In class B the division between network and host is
like this this. Address starts with 1 0, so just by looking at the first few bits you can identify
30

class A and class B. The next 14 bits represent the network and the last 16 bits represent the
host. So total number of networks will be 2 to the power 4 again 1 less than that 16383 and
total number of hosts will be last 16 bits 2 to the power 16 take out the all zero and all one
combination it is 65534. And if you just put all zeros and all ones and convert it to dotted
decimal notation you will see that the range of address is that comes here is 128 000 up to
191, 255, 255, 255. This is the range of addresses in class B networks. Now class C network
represents the ones which are smallest in size for most purposes class C networks are
sufficient for our purpose. There the number of computes is host in a network can be up to
254. Now let us see the break up.
Class C address

m
o
.c
a
m
a
n
Here the address starts with 110 in order to distinguish it from class A or class B. Next 20 bits

y
represent the network; last 8 bit represents the host. So you can have very large number of

d
class C networks of the order of 2 million. But the number of hosts in each network is only

u
254 addresses in the range 192.0.0.0 up to 223.255.255.255, they belong to the class C

t
address category.

S
Class D address
31

Now lastly is class D address. Well I am not going the detail of this now. The class address is
will start with 1110 and after that whatever you specify here this will identify the address of a
group. This is sometimes called a multicast address so depending upon what is the group
address I am giving. The packet will be broadcast to all members of that group. This is the
idea, so address range is this. Now you see just by looking at IP address you can identify which
address category the address belongs to. Given an IP address, you look at only the first few
bits of the address the rule is very simple. If the first bit is 0, if it is zero then you can it is class
A. If it is 10 then you can say it is class B and if it is 110 then you can say it is class C. There is
no ambiguity; just the first few bits uniquely identify the address classes. Depending on the
bits the routers or the intermediate nodes can easily identify the address classes and

m
accordingly perform or take the routing decisions. Now in terms of the number of addresses
o
in the whole 2 to the power 32 bit address space of an IP address. Let see how much this

.c
classes A, B or C consume. See in class A the first bit starts with 0. So we are taking away half
of the total addresses.
a
m
a
Introduction World Wide Web (WWW)

n
WWW

y
The terms Internet and World Wide Web are often used in every-day speech without much

d
distinction. However, the Internet and the World Wide Web are not one and the same. The

u
Internet is a global system of interconnected computer networks. In contrast, the Web is one

t
of the services that runs on the Internet. It is a collection of interconnected documents and

S
other resources, linked by hyperlinks and URLs. In short, the Web is an application running on
the Internet. Viewing a web page on the World Wide Web normally begins either by typing
the URL of the page into a web browser, or by following a hyperlink to that page or resource.
The web browser then initiates a series of communication messages, behind the scenes, in
order to fetch and display it.First, the server-name portion of the URL is resolved into an IP
address using the global, distributed Internet database known as the Domain Name System
(DNS). This IP address is necessary to contact the Web server. The browser then requests the
resource by sending an HTTP request to the Web server at that particular address. In the case
32

of a typical web page, the HTML text of the page is requested first and parsed immediately
by the web browser, which then makes additional requests for images and any other files that
complete the page image.
While receiving these files from the web server, browsers may progressively render the page
onto the screen as specified by its HTML, Cascading Style Sheets (CSS), or other page
composition languages. Any images and other resources are incorporated to produce the on-
screen web page that the user sees. Most web pages contain hyperlinks to other related
pages and perhaps to downloadable files, source documents, definitions and other web
resources. Such a collection of useful, related resources, interconnected via hypertext links is
dubbed a web of information. Publication on the Internet created what Tim Berners-Lee first
called the WorldWideWeb. m
Linking o
.c
Graphic representation of a minute fraction of the WWW, demonstrating hyperlinks Over

a
time, many web resources pointed to by hyperlinks disappear, relocate, or are replaced with

m
different content. This makes hyperlinks obsolete, a phenomenon referred to in some circles

a
as link rot and the hyperlinks affected by it are often called dead links. The ephemeral nature

n
of the Web has prompted many efforts to archive web sites. The Internet Archive, active

y
since 1996, is one of the best-known efforts.

d
Dynamic updates of web pages

u
JavaScript is a scripting language that was initially developed in 1995 by Brendan Eich, then

t
of Netscape, for use within web pages. [22] The standardized version is ECMAScript. [22] To

S
overcome some of the limitations of the page-by-page model described above, some web
applications also use Ajax (asynchronous JavaScript and XML). JavaScript is delivered with
the page that can make additional HTTP requests to the server, either in response to user
actions such as mouse-clicks, or based on lapsed time. The server's responses are used to
modify the current page rather than creating a new page with each response. Thus the server
only needs to provide limited, incremental information. Since multiple Ajax requests can be
handled at the same time, users can interact with a page even while data is being retrieved.
Some web applications regularly poll the server to ask if new information is available. [23]
33

Caching
If a user revisits a Web page after only a short interval, the page data may not need to be re-
obtained from the source Web server. Almost all web browsers cache recently obtained data,
usually on the local hard drive. HTTP requests sent by a browser will usually only ask for data
that has changed since the last download. If the locally cached data are still current, it will be
reused. Caching helps reduce the amount of Web traffic on the Internet. The decision about
expiration is made independently for each downloaded file, whether image, stylesheet,
JavaScript, HTML, or whatever other content the site may provide. Thus even on sites with
highly dynamic content, many of the basic resources only need to be refreshed occasionally.
Web site designers find it worthwhile to collate resources such as CSS data and JavaScript into

m
a few site-wide files so that they can be cached efficiently. This helps reduce page download
times and lowers demands on the Web server. o
.c
a
m
a
n
y
d
u
t
S
34

Unit-01/Lecture-04
Working of web browser and web server: [RGPV/Jun 2014(7)]
LIKE much of the Internet, the World Wide Web operates on a client/server model. You run
a web client on your computer—called a web browser—such as Microsoft’s Internet
Explorer or Firefox. That client contacts a web server and requests information or resources.
The web server locates and then sends The information to the web browser, which displays
the results.
When web browsers contact servers, they’re asking to be sent pages built with Hypertext
Markup Language (HTML). Browsers interpret those pages and display them on your

m
computer. They also can display applications, programs, animations, and similar material

o
created with programming languages such as Java and ActiveX, scripting languages such as
JavaScript, and techniques such as AJAX.
.c
a
Sometimes, home pages contain links to files the web browser can’t play or display, such as
sound or animation files. In that case, you need a plug-in or a helper application. You
m
configure your web browser or operating system to use the helper application or plug-in
a
whenever it encounters a sound, animation, or other type of file the browser can’t run or

n
play. Over the years, web browsers have become increasingly sophisticated. Browsers are

y
now full-blown software suites that can do everything from videoconferencing to letting you

d
create and publish HTML pages.

u
Browsers now also blur the line between your local computer and the Internet—in essence,
t
S
they can make your computer and the Internet function as a single computer system.
Increasingly, a browser is not just a single piece of software, but an entire suite. The newest
version of Internet Explorer, for example, includes security features such as an anti-phishing
filter. The Firefox browser has a companion piece of email software called Thunderbird that
can be downloaded as well.
When browsing the Internet, one of the most frustrating experiences is the error messages
browsers display when they’re having trouble contacting a website. Depending on which
browser you use, and which version of the browser you’re using, those messages might
35

differ. Sometimes browsers display error messages in plain English—but more often they
don’t. The final illustration in this chapter lists the most common browser error messages—
and what they mean.
How a Web Browser Works?
1) Web browsers consist of client software that runs on your computer and displays
home pages on the Web. There are clients for a wide variety of devices, including
Windows, Macintosh, and Unix computers.
2) A web browser displays information on your computer by interpreting the Hypertext
Markup Language (HTML) that is used to build home pages on the Web. Home pages
usually display graphics, sound, and multimedia files, as well as links to other pages,
files that can be downloaded, and other Internet resources. m
o
3) The coding in the HTML files tells your browser how to display the text, graphics,

.c
links, and multimedia files on the home page. The HTML file your browser loads to

a
display the home page doesn’t actually have the graphics, sound, multimedia files,

m
and other resources on it. Instead, it contains HTML references to those graphics and

a
files. Your browser uses those references to find the files on the server and then

n
display them on the home page.

y
4) The web browser also interprets HTML tags as links to other websites, or to other

d
web resources, such as graphics, multimedia files, newsgroups, or files to download.

u
Depending onthe link, it performs different actions. For example, if the HTML code

t
specifies the link as another home page, the browser retrieves the URL specified in

S
the HTML file when the user clicks the underlined link on the page. If the HTML code
specifies a file to be downloaded, the browser downloads the file to your computer.
How do web servers work?
What happens when you enter in the address field of your browser the URL
http://www.aprelium.com/doc/sample.html?
First, the browser slices the URL in 3 parts:
 http://: This part indicates that the document you want to access can be retrieved
from web server, which understands the HTTP protocol. The HTTP protocol is a
36

standardized language of communication between browsers and web servers.


 www.aprelium.com: This is the host name of the computer from which the
document can be downloaded.
 /doc/sample.html: This is the virtual path of the document in the
www.aprelium.com's web server.
Then, the browser contacts a DNS (Domain Name Server) to know the IP address of the
computer which full qualified domain name is www.aprelium.com. The domain name server
is usually run by your ISP or by your company.
The browser establishes a connection channel with the web server on the computer which
IP address was given by the DNS server and requests the document on the host which name
m
is www.aprelium.com and which virtual path is doc/sample.html. The browser has to specify
o
in the request the host name because many modern web servers (including Abyss Web

.c
Server) have the ability to serve more than a one host from a single computer with a single

a
IP address only. This is called virtual hosting. In such a case, the IP address of this computer

m
is associated with more than one domain name.

a
The server decodes the request and maps the virtual path to a real one, which should match

n
an existing file. The server sends the file to the browser with some useful information such

y
as its last modification time and its MIME type. The MIME type helps the browser decide

d
how to display the received document. In our example, it is a HTML file. So the server sets

u
its MIME type to text/html and the browser understands that it must render it as text.

t
Sometimes you enter a URL without an explicit filename such as

S
http://www.aprelium.com/doc. The browser sends the request to the web server as in the
previous example. The server detects that the virtual path maps to a directory and not to a
file. It searches then in this directory an index file. Index files are usually named index.html
or index.htm. If it finds for example index.html, it acts as if the requested URL was
http://www.aprelium.com/doc/index.html. If no index file is found, the web server generates
a listing of the directory contents and sends it to the browser or reports an error.
What is the role of web server on the Internet?: [RGPV/Jun 2014(7),Jun 2012(5)]
Web servers - the computer or the program - have a vital role on the Internet. The Server
37

machine hosts (stores) the web site on its hard disk while the server program helps deliver
the web pages and their associated files like images, flash movies etc. to clients (browsers).
The process of loading a web site/page in a web browser starts with the user either entering
the URL in the address bar or clicking on a link. You should know that each web page has a
unique address (or URL) on the internet; which means the same page cannot exist in two
places. (If a copy does exist in another location, its address would be different from that of
the original).
Once the appropriate action has been initiated by the user, the browser sends out a request
for the web page. Behind the scenes, the URL of the requested web page is resolved into an
I.P. address, which, in English, means, converted to an I.P. address - something that

m
computers understand. The I.P. address points to the location of the web site host. The
o
request is forwarded to Server computer and passed on to the server software.

.c
The server software now gets to work and hunts for the requested web page on the hard

a
disk. On finding the file, it sends a response to the browser followed the actual web page file

m
which then starts displaying the page.

a
A typical web page not only has text but also embedded multimedia elements like images

n
and Flash animation. These "extra" files are separate from the actual web page and are

y
fetched by the browser from the Server one by one. Note (and an important one), ONLY the

d
web browser determines how a web page is displayed; the web server has no control over

u
this. The job of the web server ends once the requests from the browser are processed and

t
the required information is sent.

S
Though it might seem that the request-and-response process takes a lot of time, especially
when you consider that the client and server computers might be thousands of miles apart,
it actually happens very fast. That's because of the HyperText Transfer Protocol (HTTP) which
is a set of rules developed by the "big lads" to facilitate the transfer of data over the
internet.
Apache HTTP Server
First released in 1995, the Apache HTTP Server is a free open-source Web server developed
under the governance of the Apache Software Foundation. The Apache 2.0 license permits
38

bundling with commercial software and does not require derivative works to be open
source.
A variety of developers make code contributions to the project, including members of the
Apache Software Foundation, developers who are allowed or instructed to work on Apache
by their corporate employers, and even individuals contributing to Apache on their own
time. Companies that use Apache range from start-ups to long-established large
enterprises. Apache is used for intranets and public facing Web sites.
Apache is a key component in what’s known as the LAMP stack, which comprises the
Linux operating system; the Apache Web server; the MySQL database; and either PHP, Perl,
or Python programming language. While people often perceive Apache as a Linux Web
server, it also runs on Windows. m
Internet Information Server 6.0 o
.c
With Windows Server 2003, Microsoft introduced Internet Information Server (IIS) 6.0,

a
which has proven to be a very secure Web server, with only four vulnerabilities reported

m
since its release in 2003. IIS security results from Microsoft investing in the Security

a
Development Lifecycle, an end-to-end approach to security that typically reduces both the

n
total number and the severity of vulnerabilities in software built using that methodology.

y
This isn’t to say that Apache is not secure, as high-profile and widely available Web sites

d
wouldn’t use it if they thought it were, but simply to point out that IIS 6.0 was designed

u
with security in mind, and has a great security track record.

t
IIS 6.0 included a number of features that made it a good fit for corporations, and enabled

S
hosting providers to offer Windows Server 2003 and IIS 6.0-based solutions. It introduced
application pools to prevent one misbehaving site from taking other sites down and it also
included health monitoring that allowed administrators to configure sites for automatic
restart on failure. IIS 6.0 enhanced management by moving to a single, XML-based
configuration file (the metabase ) and by supporting more operations through a
command-line interface. IIS 6.0 used resources more efficiently, thus increasing the
performance of individual sites and allowing each server to host a greater number of sites.
Does IIS offer the performance and scalability I need?
39

IIS has proven its ability to handle the scalability and performance requirements of high-
traffic sites. Both Apache and IIS 7.0 allow administrators to optimize performance and
scalability with bandwidth throttling, compression, and some load balancing. Static and
dynamic compressions are built in to IIS 7.0 in order to use bandwidth efficiently. IIS 7.0
also supports bandwidth throttling, while Windows Server 2008 includes full featured
network load balancing.
Apache administrators are accustomed to installing Apache on a trimmed-down server
installation. Microsoft provides a similar platform for IIS with the Server Core
installation option. This option means that the operating system is using the fewest
resources possible, which makes more resources available to handle the Web workload and
m
ensures that fewer components are installed, requiring less management and maintenance.
o
.c
The modular nature of IIS also helps improve performance, allowing administrators to
enable only the modules they need, resulting in a faster processing pipeline.

a
Caching often provides the biggest performance improvement for Web sites, and IIS

m
provides built-in output caching and object caching that can automatically detect when the

a
underlying database has changed. Apache administrators will find that these IIS 7.0 features

n
are similar in functionality to the caching modules that they typically use with Apache.

y
The performance and scalability of IIS are proven by some of the most highly trafficked Web

d
sites. For example, Match.com runs IIS to process its 30 million daily page views. In 2004,

u
PlentyOfFish.com used one IIS 6.0 server running at 65 percent of capacity to handle 31

t
illio daily page ie s fro 0,000− 0,000 co curre t users ; the site curre tly ha dles

S
1.2 billion page views per month. MySpace.com runs IIS to handle the whopping 23 billion
page views it gets every month.
Is IIS as secure as Apache?
Microsoft developed Windows Server 2003 and Windows Server 2008 under its Security
Development Lifecycle (SDL), which uses education, quality gates, threat modeling, attack
surface reduction, static analysis, fuzz and penetration testing, and a final security review to
ensure that products are as secure as possible. In addition, the Microsoft Security Response
Center engages with external security researchers and is even involved in the security
40

community through its participation in, for example, the Black Hat conference. These
efforts have resulted in a substantial reduction in vulnerabilities across the Microsoft
product suite, with particularly steep reductions in OS, Web server, and database
vulnerabilities. The modular nature of IIS 7.0 further reduces the risk of exploitable flaws, as
most modules are not installed by default to keep the attack surface small.
In addition to having fewer vulnerabilities, IIS includes a number of new security features.
For example, IIS 7.0 isolates each Web site into its own sandbox to help prevent single-site
exploits and failures from compromising other sites or the entire server. The IIS process,
which executes requests from the web, run as a restricted user account by default, and does
not require administrative privileges. To further protect the Web server, IIS 7.0 includes

m
request filtering. Request filtering is a rules-based security module that inspects every
o
incoming request for malicious request patterns, such as SQL injection attacks. This prevents

.c
some malicious requests from ever reaching the core Web server.
S.NO RGPV QUESTIONS
a Year Marks

m
Q.1 Discuss the services of web servers and describe Dec.2013 7

a
the working of web browser.

n
Q.2 what are web servers? Explain the features and June.2014 7

y
characteristics used for comparison of web servers.

d
Q.3 How does the web work? Give two examples of June.2012 5

u
web servers

t
S
41

Unit-01/Lecture-05
N-tier architecture: [RGPV/Jun 2010(12]

N tier architecture means splitting up the system into N tiers, where N is a number from 1
and up. A 1 tier architecture is the same as a single process architecture. A 2 tier
architecture is the same as a client / server architecture etc.

A 3 tier architecture is a very common architecture. A 3 tier architecture is typically split


into a presentation or GUI tier, an application logic tier, and a data tier. This diagram
illustrates a 3 tier architecture:

m
o
.c
a
m
a
n
y
The presentation or GUI tier contains the user interface of the application. The presentation
d
tier is "dumb", meaning it does not make any application decisions. It just forwards the

u
user's actions to the application logic tier. If the user needs to enter information, this is

t
done in the presentation tier too.

S
The application logic tier makes all the application decisions. This is where the "business
logic" is located. The application logic knows what is possible, and what is allowed etc. The
application logic reads and stores data in the data tier.

The data tier stores the data used in the application. The data tier can typically store data
safely, perform transactions, search through large amounts of data quickly etc.

Web And Mobile Applications

Web applications are a very common example of 3 tier applications. The presentation tier
consists of HTML, CSS and JavaScript, the application logic tier runs on a web server in form
of Java Servlets, JSP, ASP.NET, PHP, Ruby, Python etc., and the data tier consists of a
42

database of some kind (mysql, postgresql, a noSQL database etc.). Here is a diagram of a
typical 3 tier web application:

m
o
.c
Actually, it is the same principle with mobile applications that are not standalone
a
applications. A mobile application that connects to a server typically connect to a web server
and send and receive data. Here is a diagram of a typical 3 tier mobile application:

m
a
n
y
d
u
t
S
Rich Internet Applications (RIA)
In the first generations of web applications a lot of the HTML, and parts of the CSS and
JavaScript was generated by scripts running on the web server. When a browser requests a
certain page on the web server, a script was executed on the web server which generated
the HTML, CSS and JavaScript for that page.
43

Today the world is moving to rich internet applications (RIA). RIA also uses a 3 tier
architecture, but all the HTML, CSS and JavaScript is generated in the browser. The browser
has to download the initial HTML, CSs and JavaScript files once, but after that the RIA client
only exchanges data with the web server. No HTML, CSS or JavaScript is sent forth and back
(unless that is part of the data, like with an article that contains HTML codes).
RIA applications are explained in more detail in the next text in the software architecture
trail.

Web Application Advantages


The purpose of N tier architecture is to insulate the different layers of the application from

m
each other. The GUI client doesn't know how the server is working internally, and the server
o
doesn't know how the database server works internally etc. They just communicate via
standard interfaces.
.c
a
Web applications especially have another advantage. If you make updates to the GUI client

m
or the application logic running on the server, all clients get the latest updates the next time

a
they access the application. The browser downloads the updated client, and the updated

n
client accesses the updated server.

y
d
Significance of Tiers

u
• N-tier architectures have the same components

t
Presentation

S
Business/Logic
Data
• N-tier architectures try to separate the components into different tiers/layers
Tier: physical separation
Layer: logical separation
44

1-Tier Architecture

• All 3 layers are on the same machine


All code and processing kept on a single machine
m
• Presentation, Logic, Data layers are tightly connected
o
.c
Scalability: Single processor means hard to increase volume of processing

a
Portability: Moving to a new machine may mean rewriting everything

m
Maintenance: Changing one layer requires changing other layers

2-Tier Architecture a
n
y
d
u
t
S
• Database runs on Server
Separated from client
Easy to switch to a different database
• Presentation and logic layers still tightly connected
Heavy load on server
45

Potential congestion on network


Presentation still tied to business logic

3-Tier Architecture

m
o

.c
Each layer can potentially run on a different machine
• Presentation, logic, data layers disconnected
a
m
a
A Typical 3-tier Architecture

n
y
d
u
t
S

Architecture Principles
46

• Client-server architecture
•Each tier (Presentation, Logic, Data) should be independent and should not expose
dependencies related to the implementation
•Unconnected tiers should not communicate
•Change in platform affects only the layer running on that particular platform
Presentation Layer
Provides user interface
•Handles the interaction with the user
•Sometimes called the GUI or client view or front-end
•Should not contain business logic or data access code
m
Logic Layer
o
.c
•The set of rules for processing information
•Can accommodate many users
Sometimes called middleware/ back-end a
m
•Should not contain presentation or data access code
Data Layer a
n
•The physical storage layer for data persistence

y
•Manages access to DB or file system

d
• Sometimes called back-end
u
t
•Should not contain presentation or business logic code

S
The 3-Tier Architecture for Web Apps
Presentation Layer
->Static or dynamically generated content rendered by the browser (front-end)
Logic Layer
->A dynamic content processing and generation level application server, e.g., Java EE,
ASP.NET, PHP, ColdFusion platform (middleware)
Data Layer
->A database, comprising both data sets and the database management system or RDBMS
47

software that manages and provides access to the data (back-end)


3-Tier Architecture – Advantages
• Independence of Layers
Easier to maintain
Components are reusable
Faster development (division of work)
Web designer does presentation
Software engineer does logic
DB admin does data model

S.NO RGPV QUESTIONS m


Year Marks
Q.1 Explain three tier web architecture with suitable diagram o
June.2010 12

.c
a
m
a
n
y
d
u
t
S
48

UNIT-01/LECTURE-06
Services of web server
A Web server is a program that, using the client/server model and the World Wide Web's
Hypertext Transfer Protocol ( HTTP ), serves the files that form Web pages to Web users
(whose computers contain HTTP clients that forward their requests). Every computer on the
Internet that contains a Web site must have a Web server program. Two leading Web
servers are Apache , the most widely-installed Web server, and Microsoft's Internet
Information Server ( IIS ). Other Web servers include Novell's Web Server for users of its
NetWare operating system and IBM's family of Lotus Domino servers, primarily for IBM's

m
OS/390 and AS/400 customers.

o
Apache is the most popular UNIX web server today. Apache was originally based on code

.c
and ideas found in the most popular HTTP server of the time, NCSA httpd 1.3 (early 1995). It
has since evolved into a far superior system which can rival (and probably surpass) almost

a
any other UNIX based HTTP server in terms of functionality, efficiency and speed. Take a

m
look at the web server feature chart to see how Apache ranks among the competition.Open

a
Market provides software products that are used to develop the infrastructure for Internet

n
commerce. They pride themselves on scalability, content flexibility, lower entry and

y
maintenance costs, and enhanced security.

d
Netscape sells several web server software packages. The Netscape Enterprise Server offers

u
built in advanced services such as Internet-based access controls, automatic link

t
management, and revision control. The FastTrack Server is an easy-to-use entry-level Web

S
server designed to let novices create and manage a Web site.
IBM's Secure Server is provided for AIX, HP-UX, and Solaris, as well as NT and OS/2. Version
4.2 servers include enhanced scalability, browser-specific response capability, enhanced CGI
support, PICS support, and HTTP Version 1.1 compliance. The IB servers have consistent
configuration, management, and API interfaces across all of their supported platforms.
Jigsaw is W3C's sample implementation of HTTP, a full blown HTTP server entirely written in
Java. Its design goals were: will run on any machine running Java, can be extended by
writing new resource objects (a replacement for CGI), minimization of file system accesses.
49

WebSTAR is a Mac HTTP server which performs dynamic web server file caching, has the
ability to run server side Java applets, contains an administration plug-in that lets one
administer essential server functions from any web browser on the Internet, honors keep-
alive requests, supports a 20,000 username/passwd database, has integrated support for
image maps, supports common log format, supports cgi-bin folder, does on the fly bin-
hexing of Mac files, and supports an expanded command set for server-side includes.

Common gateway interface (CGI) : [RGPV/Jun 2012,14(7)]


An HTTP server is often used as a gateway to a legacy information system; for example, an
existing body of documents or an existing database application. The Common Gateway

m
Interface is an agreement between HTTP server implementors about how to integrate such
gateway scripts and programs. o
.c
It is typically used in conjunction with HTML forms to build database applications.

a
The Common Gateway Interface (CGI) is a standard for interfacing external applications with

m
information servers, such as HTTP or Web servers. A plain HTML document that the Web

a
daemon retrieves is static, which means it exists in a constant state: a text file that doesn't

n
change. A CGI program, on the other hand, is executed in real-time, so that it can output

y
dynamic information.

d
For example, let's say that you wanted to "hook up" your Unix database to the World Wide

u
Web, to allow people from all over the world to query it. Basically, you need to create a CGI

t
program that the Web daemon will execute to transmit information to the database engine,

S
and receive the results back again and display them to the client. This is an example of a
gateway, and this is where CGI, currently version 1.1, got its origins.
The database example is a simple idea, but most of the time rather difficult to implement.
There really is no limit as to what you can hook up to the Web. The only thing you need to
remember is that whatever your CGI program does, it should not take too long to process.
Otherwise, the user will just be staring at their browser waiting for something to happen.
As you traverse the vast frontier of the World Wide Web, you will come across documents
that make you wonder, "How did they do this?" These documents could consist of, among
50

other things, forms that ask for feedback or registration information, imagemaps that allow
you to click on various parts of the image, counters that display the number of users that
accessed the document, and utilities that allow you to search databases for particular
information. In most cases, you'll find that these effects were achieved using the Common
Gateway Interface, commonly known as CGI.
One of the Internet's worst-kept secrets is that CGI is astoundingly simple. That is, it's trivial
in design, and anyone with an iota of programming experience can write rudimentary scripts
that work. It's only when your needs are more demanding that you have to master the more
complex workings of the Web. In a way, CGI is easy the same way cooking is easy: anyone
can toast a muffin or poach an egg. It's only when you want a Hollandaise sauce that things
start to get complicated. m
o
CGI is the part of the Web server that can communicate with other programs running on the

.c
server. With CGI, the Web server can call up a program, while passing user-specific data to

a
the program (such as what host the user is connecting from, or input the user has supplied

m
using HTML form syntax). The program then processes that data and the server passes the

a
program's response back to the Web browser.

n
CGI isn't magic; it's just programming with some special types of input and a few strict rules

y
on program output. Everything in between is just programming. Of course, there are special

d
techniques that are particular to CGI, and that's what this book is mostly about. But

u
underlying it all is the simple model shown in Figure.

t
S

Simple diagram of CGI


CGI Applications
CGI turns the Web from a simple collection of static hypermedia documents into a whole
new interactive medium, in which users can ask questions and run applications. Let's take a
51

look at some of the possible applications that can be designed using CGI.
Forms
One of the most prominent uses of CGI is in processing forms. Forms are a subset of HTML
that allow the user to supply information. The forms interface makes Web browsing an
interactive process for the user and the provider. Figure shows a simple form.
Figure: Simple form illustrating different widgets

m
o
.c
a
m
a
n
As can be seen from the figure, a number of graphical widgets are available for form

y
creation, such as radio buttons, text fields, checkboxes, and selection lists. When the form is

d
completed by the user, the Submit Order! button is used to send the information to the

u
server, which executes the program associated with the particular form to "decode" the
t
S
data.

Generally, forms are used for two main purposes. At their simplest, forms can be used to
collect information from the user. But they can also be used in a more complex manner to
provide back-and-forth interaction. For example, the user can be presented with a form
listing the various documents available on the server, as well as an option to search for
particular information within these documents. A CGI program can process this information
and return document(s) that match the user's selection criteria.
52

Gateways
Web gateways are programs or scripts used to access information that is not directly
readable by the client. For example, say you have an Oracle database that contains baseball
statistics for all the players on your company team and you would like to provide this
information on the Web. How would you do it? You certainly cannot point your client to the
database file (i.e., open the URL associated with the file) and expect to see any meaningful
data.
CGI provides a solution to the problem in the form of a gateway. You can use a language
such as oraperl (see Chapter 9, Gateways, Databases, and Search/Index Utilities, for more

m
information) or a DBI extension to Perl to form SQL queries to read the information
o
contained within the database. Once you have the information, you can format and send it

.c
to the client. In this case, the CGI program serves as a gateway to the Oracle database, as
shown in Figure
a
m
Figure: A gateway to a database

a
n
y
d
u
t
S

Virtual Documents
Virtual, or dynamic, document creation is at the heart of CGI. Virtual documents are created
53

on the fly in response to a user's information request. You can create virtual HTML, plain
text, image, and even audio documents. A simple example of a virtual document could be
something as trivial as this:
Welcome to Shishir's WWW Server!
You are visiting from diamond.com. The load average on this machine is 1.25. Happy
navigating! In this example, there are two pieces of dynamic information: the alphanumeric
address (IP name) of the remote user and the load average on the serving machine. This is a
very simple example, indeed!
On the other hand, very complex virtual documents can be created by writing programs that
use a combination of graphics libraries, gateways, and forms. As a more sophisticated

m
example, say you are the manager of an art gallery that specializes in selling replicas of
o
ancient Renaissance paintings and you are interested in presenting images of these

.c
masterpieces on the Web. You start out by creating a form that asks for user information for

a
the purpose of promotional mailings, presents a search field for the user to enter the name

m
of a painting, as well as a selection list containing popular paintings. Once the user submits

a
the form to the server, a program can email the user information to a certain address, or

n
store it in a file. And depending on the user's selection, either a message stating that the

y
painting does not exist or an image of the painting can be displayed along with some

d
historical information located elsewhere on the Internet.

u
Along with the picture and history, another form with several image processing options to

t
modify the brightness, contrast, and/or size of the picture can be displayed. You can write

S
another CGI program to modify the image properties on the fly using certain graphics
libraries, such as gd, sending the resultant picture to the client.
This is an example of a more complex CGI program using many aspects of CGI programming.
S.NO RGPV QUESTION YEAR MARKS
Q.1 Write a brief notes on common June.2014 07
gateway interface
Q.2 What is CGI? What are the June.2012 05
limitations in developing CGI
54

application?

m
o
.c
a
m
a
n
y
d
u
t
S
55

UNIT-01/LECTURE-07
Uniform Resource Locator (URL): : [RGPV/Jun 2012(10)]
URL are nothing but mechanisms to locate some resource on the internet. In the simple case
I want to locate that particular file in the wed server that is the example of URL. URL is the
short form for Uniform Resource Locator.

m
o
.c
a
URL is a mechanism or it is a format whatever you call by which documents or resources can

m
be addressed in the internet in the World Wide Web. A URL contains several information.

a
First of course the name or the address of the site or the server where the actual resource

n
you are trying to address is located. Secondly what is the type of service you want to use to

y
access the resource? Do you want to use Http. So you want to use http or something else.

d
Port number of the service well in most cases some default port number is assumed. But

u
you can explicitly specify a port number also and once you have look at it or specified

t
everything. You may also specify a path name on the server which specifies where the

S
resource is located on that particular server. So all this things taken together will actually
identify where the server will actual where the particular resource you are trying to address
is actually located on the server.
56

m
o
Now let us see what are the different URL types. These URLs are nothing but a form of

.c
specifying internet addresses. So the whatever you have specified, it starts with a scheme
this is the syntax scheme which access method you are using followed by a colon double
a
slash where there is one example, where you do not need the double slash followed by the

m
address of the machine. This colon port is optional if you want to specify an explicit port

a
number give colon port followed by a path name some examples follow.

n
The first example is a URL which says it is an http. This is the name of the server and this is

y
the path of the resource the resource is ab1.html. The second one is also http, but it specify

d
an explicit port number here the http server is running on port number 2345. The resource

u
is rose.jpg in this path. The third is an example of an email mail to at the end you have the

t
email address. Well if you have this mail to URL as a part of a web page. If you click on it

S
automatically a mail window will open where you can type in a mail. This is the reason why
mail to URL is required.
NEWS is one example where double slash is not required. This refers to NEWS groups FTP is
for file transfer in the first case after the slash, you give the user name colon; you give the
password, then this at the rate sign. Then the machine where you want to do a FTP then this
the path name where the path name or resource is located. The last example refers to
anonymous ftp. But user name and password are not given so if the user name and
57

password are missing then by default it is taken to the anonymous FTP and this is the
address of a machine and this is the address of the document or resource under the
anonymous directory.
Sending a Query String

m
o
.c
And this URL can also be used to send a send query string like the example that we had

a
given earlier for GET. Well GET is a way to send it as a as a http string. But even when you
type a URL on the browser there also you can explicitly specify that. Like an example follows,

m
it says http. This is the name of the machine; this is the path name of the resource. Here this

a
path name refers to a cgi program again a question mark followed by some additional

n
information. Now this whole thing is a URL. This you can type on a browser and press enter.

y
What the browser will do it will generate a get http request from this and it will send it to

d
the requested server. So actually what will go to the server will be the same GET request as I

u
mentioned earlier. But this how you can also specify in an URL as part of http. So with this

t
we come to the end of first part of our discussion on World Wide Web. Now let us quickly

S
have a look at the answers to the questions that where POST in our last class.
S.NO RGPV QUESTION YEAR MARKS
Q.1 What is URL? Explain URL Syntax with June.2012 10
example. Also explain three parts of
URL.
58

UNIT-01/LECTURE-08
Hyper Text Transfer Protocol (HTTP): : [RGPV/Dec 2013(7)]

m
o
.c
Now this http is the driving force behind the World Wide Web. So when we talk about the

a
World Wide Web; when you talk about web server it is the http protocol we are talking

m
about. So the web server is running a program which is understanding the http protocol any

a
client can send http request it will get back a http response or reply. So let us say what this

n
http request and response is look like. So first let us try to understand http. The hypertext

y
transport protocol transfer protocol these are protocol which the web clients which the

d
browsers are typical example of web clients interact with web servers. This is the language

u
using which a browser and a web server talk along with themselves. The hypertext transfer

t
protocol the first version at least it is a stateless protocol stateless protocol means no history

S
is maintained. Every time a request is sent a fresh connection has to be established.
If you are requesting for three documents from the same server you have to establish
connection three times. Not that you are connecting only once and transferring three
documents at the same time. There are of course some subsequent versions of http which
allows the so called persistent connections where you can make multiple transactions over a
single connection. This http hypertext across the internet sees the documents that are
stored in the webpage. As I said they are some pages with links to other pages. These are
called hypertext, so hypertexts are texts with links to other documents. So this http protocol
59

allows transfer from one document to another using this hyper text by clicking a link you can
go to some other place. There should be a mechanism in built in the http protocol which
should support this kind of a thing.
HTTP Protocol

m
So as I mentioned browsers and web server communicate using http the basic steps look like

o
this. The client first opens a socket connection to the http server typically the http server

.c
runs over port number 80 but some web servers also run over some other port number like

a
8080 or something else also. So you must know the port number on which the server is
running. So that you can establish a connection to it typically by default the port number is

m
80. So after connection establish the client sends http request to the server. Server will send

a
back response and the server will immediately close down the connection. This is the state

n
less mode. For every connection you are opening and closing the connection, there is

y
another request then the whole process will we will have to repeat it again. Again start a

d
connection, again transact and then close.
Illustration
u
t
S

So just look at this diagram, suppose you are sitting here. This is a web client here you are
using a browser here when you are typing the address of the site say www.yahoo.com, say
this is the yahoo.com server. So an http request has been sent to the yahoo.com server and
60

the server sends back a response which is actually an html page which gets displayed on
your screen. Now after the html page comes back on your page and if you click on one of
those so called hyper link switch which links to other documents. Then what happens? Now
another http request goes to fix the other document the other document is possibly residing
in some other web server and that some other web server will again be sending you back
response and this will continue. Sending a request getting back a response clicking a link
going to some other server, this continues. This is called web browsing and this browsing can
take you to one server to another across the world. You really do not know that where you
have started and where you have ultimately stops in this process.

HTTP Request Format m


o
.c
a
m
a
n
y
d
Now talking about the http request format a client request to the server consists of the

u
following. It consists of a request method there are several request methods we shall be
t
talking about get head POST port etcetera. The path position of the http URL is URL is a way
S
of specifying the path we shall be talking about URL later in the lecture. Version number of
the http protocol and for some of the request methods you may need some optional header
information and in case you need to supply some additional data. The data has to be
supplied after a blank line in between. This blank line acts as a delimiter between the
header portion and the additional data that you are supplying. Some of the request
methods like POST or PUT, they need the additional data. But for those method which do
not need the data that part may not be there.
61

HTTP Request Methods

m
So let us look at some of the important request methods one by one. GET is the most widely

o
used method this is the method which is used to fetch a web page from a server. It returns

.c
the contents of the specified document. GET can place any parameter that you need in the

a
request header itself. It does not need any additional lines of header information like an
example is shown here. This, the get command here we are putting some additional
m
information out here followed by the http version number. You see the first part of it cgi bin
a
myscript.cgi specifies a path to a particular resource myscript.cgi. But after that following

n
this question mark there is some additional data roll is equal to 1264 amber cent sex equal

y
to m. This actually comes from so called forms. Well we shall be studying forms later when

d
you study html in detail.

u
t
S
See form is something like you have seen many work pages like the search engines where
some blank form like place come where you can type in something press enter or search
something else comes back. So whatever you are typing in those boxes empty boxes and
pressing enter you are actually filling up a form and submitting it when the data goes back
to the web server it goes in this form. For example there was one space for roll no one place
of sex I have typed in 1234 and m and this what which goes. This is the data you get filling
you physically fill up in the form and the way this roll number is equal to amber sent this is
called URL. It is URL encoding this we shall study detail when you talk about cgi scripting and
62

html forms later in course. Of this lecture but this example shows how you can give this kind
of information along with the get command.
Illustration of GET

m
o
.c
a
Now a very simple illustration of GET server trying to retrieve a simple documents no

m
sending of form data. A simple document see to start with it you can just open a command

a
window again and you can start this transaction. You can give a command telnet you can

n
give the name of the server to which you want to connect and http you can either give http

y
or you can give the default port number 80 whatever. This http will mean that the default

d
port number of the http protocol well after this connection is done. You will get back a

u
screen with nothing displayed which means that the server is expecting you to type

t
something. So you type a command like this get is the request method slash test dot html is

S
the document you are requesting and this is the version of the http.

The server will be sending back a response like this. First you see there are several lines of
header http. The http version name of the server it is running 1.1 version date server type
last modified this document when it was last modified. Accept ranges of course this is a
optional we will talk about it later content length what is the size of the document
connection close. Means this is the default approach that means after the transaction is
over you tell me the d http connection. This is the so called stateless approach that I was
63

talking about. So instead of close you can also specify connection keep alive that is
supported in the http version 1.1 or you can leave the connection open by default.
Illustration of GET(Cont..)

m
And after these lines come this content type. These are text of type html here there is a

o
blank line you see there is a blank line in between this blank line indicates or it acts a

.c
delimiter that now the actual data follows. So the actual content of the file follows after this.

a
This is a free simple html file which is created to give you this demonstration. So the content
of the html file will come after that. So you see that this command get command can be

m
used to fetch an html file from a server if you know of course the name of the file.

a
n
y
d
u
t
S
There is another request method called head which returns only the header information.
Well you may not be interested to get the whole file; but you need some information about
the file like the file size when was it last modified server version etcetera.
Illustration of HEAD
64

m
So a typical session with head will look like this after doing the telnet, you send a command

o
like this. Head name of a file followed by http version you get back only the header portion.

.c
What is missing is actually the body of the contents of the file that you are not requesting
here. You are requesting only the header portion. So only the header portion is coming back

a
to you and you can have a look at the header position to see what it contains. If example
this, file size is 1494 bytes.
m
a
n
y
d
u
t
S
POST is another request method. POST is again another method which is used in
conjunction with the submission of the form. So we will be talking about POST now. But you
can actually put it in a proper cont to a context when we discuss suggest script later during
our class. Now this POST is used to send some additional data to the server to be processed
typically by a cgi script; cgi script is a program cgi stands for common gateway interface it is
a program which running on the server side. Whenever you fill up a form typically the data
65

in the form goes to the cgi script; the cgi script reads the data and does some processing
and generates some output which comes back to the client and the browser. It gets
displaced there; this is how cgi scripts work. Now this POST request method allows you send
data to the cgi script, but the why this data sent is different from the gate approach that we
have discussed. But this uses two addition header type; content type and content length.

m
o
The requested object is not a resource to retrieve. Rather it is a script an executable script.

.c
Similarly server response which comes back is not a static file. But rather it is the output of

a
the cgi program which I have seen. So the server is not sending you back the contents of a
file which already there. Rather it is sending you back the output of that cgi program. For

m
instance which is receiving the data executing it and sending back the output to you?

a
S.NO RGPV QUESTION
n YEAR MARKS
Q.1
y
What is HTTP? Write and Dec.2013 7

d
explain the structure of HTTP

u
request.

t
S
66

UNIT-01/LECTURE-09
Illustration of POST: : [RGPV/Jun 2014(7)]

m
o
.c
Now the POST command can be illustrated with the simple example. Well again after telnet,
suppose you give a command like this, POST followed by a path name. This cgi slash bin

a
myscript.cgi. This does not refer to a document or a resource which you want to download;

m
rather this is the name of the program. The cgi script program for instance which you want

a
to execute whenever this POST command is given. And this is the additional information you

n
will also have supply after POST. See, in GET or head you give a one line command and a lot

y
of response come back. But in a POST you will have to give a multiple line command. This

d
POST is the first lines followed by from you have to identify yourself from where you are

u
sending user agent the name or the version of the user agent that is running on your

t
machine, content type or type of content it is. Well application something x -www form

S
urlencoded this is an URL encoded see this is the actual content. The way this has been
encoded this is called urlencoding and the name is x www form urlencoded and content
length the total size is 32. There is a blank line in between followed by the actual body of
this additional information. So in GET this information is put on the same line after a
question mark; in POST it is put as part of the command after a blank line. Now, in POST you
can put as much material as you can. So if we have a lot of data to send, POST is the
preferred approach because in GET the total size of the string is limited by usually 256. The
maximum size of the string that the machine can support. So other request method PUT.
67

HTTP Request Methods

PUT is used to upload the contents of a webpage. It replaces the contents of the specified
m
document with the data supplied along with the command. So here the data that was
o
supplying, this you can supply exactly like the POST command. So after some initial header

.c
give a blank line, then give your entire web page which you want to upload. So the entire

a
thing will be the data you are trying to send to the server; the server will handle it and it will

m
be uploading it. But of course as you can understand. Not all web servers allow you

a
uploading facility. Only a few web server will allow to do that and of course only after proper

n
authentication. Delete is similar in a sense that this also makes updation this can delete a

y
specified document this also is not used very widely.

d
HTTP Request Header:

u
t
S
68

Only in some servers where you have proper authentication you can do that. And after
sending the request, well. There some request header you see. That means when you are
sending the request some request header information is required. Now after the initial line
GET, POST, PUT, etcetera. So a client can send any number header lines. Some of these
where illustrated with the example for POST. So after the POST command there were several
additional lines of header followed by the data that were supplied. So this is usually optional
for some request types like get you do not need it for some others you need it. Some of the
common headers types are accept. This accept followed by a string indicates at which MIME
types the client will accept. Connection. Connection is the connection type; if it is close you
are asking it to close connection after every transaction. If it keeps alive, then you are saying

m
that well it will not be stateless. You let the connection to be persistent I can send more than
o
one file one transaction over that open connection. So you can specify this as part of the
header.
.c
a
m
a
n
y
d
u
Content length of course you have seen number of bytes of data. Content type what MIME
t
type of data is there. There is a pragma header; pragma colon followed by no cache. This
S
indicates that if you are redirecting your command to a proxy server. You are saying that you
please do not send me my requested information from your cache you try to send me a
fresh copy from the original server

HTTP Request Data


69

So this pragma no cache tells you to return a fresh document well although a cached copy
may exists, you may want sometime that you want the latest updated copy from the original
server. And for command switch request we require request data like the POST and PUT. So
you will have to put a blank line followed by the actual data. So there will be the initial
header followed by a blank line then the data part. This will be the structure of your overall
http request.
HTTP Response

m
o
.c
a
m
a
Now after the request is sent, now it is time to get back the responses. So the responses
n
look similar the requests for most of them other than get. There are some standard request
y
headers followed by optional data. The responses also look very similar. There will be an
d
initial response line which is also called the status line; response status line. It consists of
u
t
three parts the http version, a three digit response code and an English phrase indicating

S
what type it is. Two examples I shown it will either be http version name 200 or version
name 404 Not Found. This 200 404 are the error codes and Not Found are the error types.
70

And after this initial status line will come, the actual content of the response. There will be
some header at the beginning followed by the actual data and again a usual there will be
blank line in between. So there will be a blank line separating them. So the header looks
very much like the http request line. There will be some header types followed by the value.
The content length, connection close, content type and at the end you will get the data that
you are requesting.
3-digit Status Code:

m
o
.c
a
m
a
n
y
And the 3 digit status code indicates anything starting with one, indicates that this is only

d
information. This is not an error message. You need not do anything special with respect to

u
this. This is just for your information some informational message. Two, anything starting
t
with 2 indicates successful transaction. Anything starting with 3 indicates that you have
S
been redirected to another URL; some servers supports redirection. Starting with 4 means
some error condition; 5 means there is some internal server error. So these kinds of errors
are reported with an error code starting with these initial digits.
Common Status Code
71

Some of the common status codes are like this 200 means OK, 301 some documentary
requesting has been moved permanently. 302 means temporarily; 40 means there is some
authorization problem may be you have not supplied the password correctly. 403, some
documents some access permissions are not there; 404 Not Found, 500 some server error.
HTTP Response Header:

m
o
.c
a
m
a
n
y
d
u
Now in the response header there are several things which are included like content length

t
you already know it specify the size of the data in bytes. Content type, again MIME type and

S
subtype what kind of data is coming. Date means the current date. Well each document that
resides on the server can also have something like an expiry date associated with it. So
whenever you are fetching a document it will also contain what is the expiry date? Some
document may contain an expiry date; some may not contain. If it contains, then we will
have a look at the expiry date and find out whether this is an absolute document or not.
There is a last modified the name is obvious what it means and set-cookie. Set-cookie is
another information which is sometimes sent back. See set-cookie followed by some name
value pair. See whenever you want to have cookie in your browser, cookie has some values
72

name and value pair which is sent from the other side which can be used by a browser to do
some kind of a local processing. Like when you are maintaining a session you use cookies
you maintain some information about the session and session id. You continuously check
whether your present session variable matches with the session id stored in the cookie. If
not you give an error message that your session is expired something like that. So this
cookie can also be sent back.
HTTP Response Data:

m
o
.c
a
m
a
And after the initial header, again there will be a blank line which will be followed by the

n
actual data. So the way the requests are send and the responses are sent back are very

y
similar. They use the mind format for the heading a blank line then followed by the data.

d
There is no upper limit to the data size. It can be very big also, but two versions of http

u
which you see around you today. This http 1.0 is the older version. But most of the

t
modern web servers use the later version 1.1 . Now in 1.0 the server typically closes

S
connection after completing a transaction that is the default. Well in 1.1 the server keeps
the connection, open it is persistent.

So it depends on the scenario that you are working in whether you want to keep it
persistent or not. See for servers which are very heavily used keeping the connection
persistent will add the load on the server. Because every machine has a maximum limit to
the number of connections that it can handle simultaneously. So if it is a persistent and
73

there are many connections which are coming and remaining because it is active for long
time, it may so happen that the maximum limit may reach and after that request which are
coming they will not be honored they will be denied. So for most servers which are pretty
popularly used they prefer to use stateless or non-persistent connection type.

Hyper Text Transfer Protocol Secure (HTTPS):


Hypertext Transfer Protocol Secure (HTTPS) is a communications protocol for secure
communication over a computer network, with especially wide deployment on the Internet.
Technically, it is not a protocol in and of itself; rather, it is the result of simply layering the
Hypertext Transfer Protocol (HTTP) on top of the SSL/TLS protocol, thus adding the security

m
capabilities of SSL/TLS to standard HTTP communications. The main motivation for HTTPS is
to prevent wiretapping and man-in-the-middle attacks. o
.c
a
The security of HTTPS is therefore that of the underlying TLS, which uses long-term public

m
and secret keys to exchange a short term session key to encrypt the data flow between

a
client and server. An important property in this context is perfect forward secrecy (PFS), so

n
the short-term session key cannot be derived from the long-term asymmetric secret key;

y
however, PFS is not widely adopted.

d
u
X.509 certificates are used to guarantee one is talking to the partner with whom one wants

t
to talk. As a consequence, certificate authorities and a public key infrastructure are

S
necessary to verify the relation between the owner of a certificate and the certificate, as
well as to generate, sign, and administer the validity of certificates. While this can be more
beneficial than verifying the identities via a web of trust, the 2013 mass surveillance
disclosures made it more widely known that certificate authorities are a weak point from a
security standpoint, allowing man-in-the-middle attacks.

In its popular deployment on the internet, HTTPS provides authentication of the website
and associated web server that one is communicating with, which protects against man-in-
74

the-middle attacks. Additionally, it provides bidirectional encryption of communications


between a client and server, which protects against eavesdropping and tampering with
and/or forging the contents of the communication. In practice, this provides a reasonable
guarantee that one is communicating with precisely the website that one intended to
communicate with (as opposed to an imposter), as well as ensuring that the contents of
communications between the user and site cannot be read or forged by any third party.

Historically, HTTPS connections were primarily used for payment transactions on the World
Wide Web, e-mail and for sensitive transactions in corporate information systems. In the
late 2000s and early 2010s, HTTPS began to see widespread use for protecting page

m
authenticity on all types of websites, securing accounts and keeping user communications,
identity and web browsing private. o
.c
a
A site must be completely hosted over HTTPS, without having some of its contents loaded

m
over HTTP, or the user will be vulnerable to some attacks and surveillance. For example,

a
having scripts etc. loaded insecurely on an HTTPS page makes the user vulnerable to attacks.

n
Also having only a certain page that contains sensitive information (such as a log-in page) of

y
a website loaded over HTTPS, while having the rest of the website loaded over plain HTTP,

d
will expose the user to attacks. On a site that has sensitive information somewhere on it,

u
every time that site is accessed with HTTP instead of HTTPS, the user and the session will

t
get exposed. Similarly, cookies on a site served through HTTPS have to have the secure

S
attribute enabled.
Overview
HTTPS is a URI scheme which has identical syntax to the standard HTTP scheme, aside from
its scheme token. However, HTTPS signals the browser to use an added encryption layer of
SSL/TLS to protect the traffic. SSL is especially suited for HTTP since it can provide some
protection even if only one side of the communication is authenticated. This is the case with
HTTP transactions over the Internet, where typically only the server is authenticated (by the
client examining the server's certificate).
75

HTTPS creates a secure channel over an insecure network. This ensures reasonable
protection from eavesdroppers and man-in-the-middle attacks, provided that adequate
cipher suites are used and that the server certificate is verified and trusted.

Because HTTPS piggybacks HTTP entirely on top of TLS, the entirety of the underlying HTTP
protocol can be encrypted. This includes the request URL (which particular web page was
requested), query parameters, headers, and cookies (which often contain identity
information about the user). However, because host (website) addresses and port numbers
are necessarily part of the underlying TCP/IP protocols, HTTPS cannot protect their

m
disclosure. In practice this means that even on a correctly configured web server,
o
eavesdroppers can infer the IP address and port number of the web server (sometimes even

.c
the domain name e.g. www.example.org, but not the rest of the URL) that one is

a
communicating with as well as the amount (data transferred) and duration (length of

m
session) of the communication, though not the content of the communication.[citation

a
needed]

n
y
Web browsers know how to trust HTTPS websites based on certificate authorities that come

d
pre-installed in their software. Certificate authorities (e.g. VeriSign/Microsoft/etc.) are in

u
this way being trusted by web browser creators to provide valid certificates. Therefore, a

t
user should trust an HTTPS connection to a website if and only if all of the following are

S
true:

The user trusts that the browser software correctly implements HTTPS with correctly pre-
installed certificate authorities.
The user trusts the certificate authority to vouch only for legitimate websites.
The website provides a valid certificate, which means it was signed by a trusted authority.
The certificate correctly identifies the website (e.g., when the browser visits
"https://example.com", the received certificate is properly for "Example Inc." and not some
76

other entity).
Either the intervening hops on the Internet are trustworthy, or the user trusts that the
protocol's encryption layer (TLS/SSL) is sufficiently secure against eavesdroppers.

HTTPS is especially important over unencrypted networks (such as WiFi), as anyone on the
same local network can "packet sniff" and discover sensitive information. Additionally, many
free to use and even paid for WLAN networks do packet injection for serving their own ads
on webpages or just for pranks, however this can be exploited maliciously, e.g., by injecting
malware and spying on users.

m
Another example where HTTPS is important is connections over Tor (anonymity network), as
o
malicious Tor nodes can damage or alter the contents passing through them in an insecure

.c
fashion and inject malware into the connection. This is one reason why the Electronic

a
Frontier Foundation and the Tor project started the development of HTTPS Everywhere,

m
which is included in the Tor Browser Bundle.

a
n
Deploying HTTPS also allows the use of SPDY, which is designed to reduce page load times

y
and latency.

d
u
It is recommended to use HTTP Strict Transport Security with HTTPS to protect users from

t
man-in-the-middle attacks.

S
HTTPS should not be confused with the little-used Secure HTTP (S-HTTP) specified in RFC
2660
Technical
Difference from HTTP:

HTTPS URLs begin with "https://" and use port 443 by default, whereas HTTP URLs begin
with "http://" and use port 80 by default.
77

HTTP is insecure and is subject to man-in-the-middle and eavesdropping attacks, which can
let attackers gain access to website accounts and sensitive information. HTTPS is designed to
withstand such attacks and is considered secure against such attacks (with the exception of
older deprecated versions of SSL).
Network layers:

HTTP operates at the highest layer of the TCP/IP model, the Application layer; as does the
SSL security protocol (operating as a lower sublayer of the same layer), which encrypts an
HTTP message prior to transmission and decrypts a message upon arrival. Strictly speaking,

m
HTTPS is not a separate protocol, but refers to use of ordinary HTTP over an encrypted
SSL/TLS connection. o
.c
a
Everything in the HTTPS message is encrypted, including the headers, and the

m
request/response load. With the exception of the possible CCA cryptographic attack

a
described in the limitations section below, the attacker can only know the fact that a

n
connection is taking place between the two parties, already known to him, the domain

y
name and IP addresses.

d
Server setup

u
t
To prepare a web server to accept HTTPS connections, the administrator must create a

S
public key certificate for the web server. This certificate must be signed by a trusted
certificate authority for the web browser to accept it without warning. The authority
certifies that the certificate holder is the operator of the web server that presents it. Web
browsers are generally distributed with a list of signing certificates of major certificate
authorities so that they can verify certificates signed by them.
Acquiring certificates
Authoritatively signed certificates may be free or cost between 8 USD and 70 USD[17] per
year (in 2012–2014). However, in the case of free certificate authorities such as CACert,
78

popular browsers (e.g. Firefox, Chrome, Internet Explorer) may not include the trusted root
certificates, which may cause untrusted warning messages to be displayed to end users.
Organizations may also run their own certificate authority, particularly if they are
responsible for setting up browsers to access their own sites (for example, sites on a
company intranet, or major universities). They can easily add copies of their own signing
certificate to the trusted certificates distributed with the browser.
There also exists a peer-to-peer certificate authority, CACert.
Use as access control
The system can also be used for client authentication in order to limit access to a web server
to authorized users. To do this, the site administrator typically creates a certificate for each

m
user, a certificate that is loaded into his/her browser. Normally, that contains the name and
o
e-mail address of the authorized user and is automatically checked by the server on each

.c
reconnect to verify the user's identity, potentially without even entering a password.
In case of compromised secret (private) key
a
m
An important property in this context is perfect forward secrecy (PFS). Possessing one of the

a
long term asymmetric secret keys used to establish an HTTPS session should not make it

n
easier to derive the short term session key to then decrypt the conversation, even at a later

y
time. Diffie–Hellman key exchange (DHE) and Elliptic curve Diffie–Hellman key exchange

d
(ECDHE) are in 2013 the only ones known to have that property. Only 30% of Firefox, Opera,

u
and Chromium Browser sessions use it, and nearly 0% of Apple's Safari and Microsoft

t
Internet Explorer sessions. From the larger internet providers only Google supports PFS

S
since 2011.
A certificate may be revoked before it expires, for example because the secrecy of the
private key has been compromised. Newer versions of popular browsers such as Google
Chrome, Firefox, Opera, and Internet Explorer on Windows Vista implement the Online
Certificate Status Protocol (OCSP) to verify that this is not the case. The browser sends the
certificate's serial number to the certificate authority or its delegate via OCSP and the
authority responds, telling the browser whether or not the certificate is still valid.
79

Limitations
SSL comes in two options, simple and mutual.
The mutual version is more secure, but requires the user to install a personal certificate in
their browser in order to authenticate themselves.[citation needed]
Whatever strategy is used (simple or mutual), the level of protection strongly depends on
the correctness of the implementation of the web browser and the server software and the
actual cryptographic algorithms supported.
SSL does not prevent the entire site from being indexed using a web crawler, and in some
cases the URI of the encrypted resource can be inferred by knowing only the intercepted
request/response size.This allows an attacker to have access to the plaintext (the publicly

m
available static content), and the encrypted text (the encrypted version of the static
content), permitting a cryptographic attack. o
.c
Because SSL operates below HTTP and has no knowledge of higher-level protocols, SSL

a
servers can only strictly present one certificate for a particular IP/port combination. This

m
means that, in most cases, it is not feasible to use name-based virtual hosting with HTTPS. A

a
solution called Server Name Indication (SNI) exists, which sends the hostname to the server

n
before encrypting the connection, although many older browsers do not support this

y
extension. Support for SNI is available since Firefox 2, Opera 8, Safari 2.1, Google Chrome 6,

d
and Internet Explorer 7 on Windows Vista.

u
From an architectural point of view:

t
An SSL/TLS connection is managed by the first front machine that initiates the SSL

S
connection. If, for any reasons (routing, traffic optimization, etc.), this front machine is not
the application server and it has to decipher data, solutions have to be found to propagate
user authentication information or certificate to the application server, which needs to know
who is going to be connected.
For SSL with mutual authentication, the SSL/TLS session is managed by the first server that
initiates the connection. In situations where encryption has to be propagated along chained
servers, session timeOut management becomes extremely tricky to implement.
With mutual SSL/TLS, security is maximal, but on the client-side, there is no way to properly
80

end the SSL connection and disconnect the user except by waiting for the SSL server session
to expire or closing all related client applications.
For performance reasons, static content that is not specific to the user or transaction, and
thus not private, is usually delivered through a non-crypted front server or separate server
instance with no SSL. As a consequence, this content is usually not protected. Many
browsers warn the user when a page has mixed encrypted and non-encrypted resources.
A sophisticated type of man-in-the-middle attack called SSL stripping was presented at the
Blackhat Conference 2009. This type of attack defeats the security provided by HTTPS by
changing the https: link into an http: link, taking advantage of the fact that few Internet
users actually type "https" into their browser interface: they get to a secure site by clicking

m
on a link, and thus are fooled into thinking that they are using HTTPS when in fact they are
o
using HTTP. The attacker then communicates in clear with the client. This prompted the

.c
development of a countermeasure in HTTP called HTTP Strict Transport Security.

a
In May 2010, a research paper by researchers from Microsoft Research and Indiana

m
University discovered that detailed sensitive user data can be inferred from side channels

a
such as packet sizes. More specifically, the researchers found that an eavesdropper can infer

n
the illnesses/medications/surgeries of the user, his/her family income and investment

y
secrets, despite HTTPS protection in several high-profile, top-of-the-line web applications in

d
healthcare, taxation, investment and web search.

u
S.NO RGPV QUESTION YEAR MARKS

t
Q.1 What is HTTP? Explain the utility and June.2014 7

S the various methods used by HTTP.


81

REFERENCE

BOOK AUTHOR PRIORITY


Web Technologies-TCP/IP 1
Architecture, and Java Achyut S. Godbole
Programming and Atul Kahate
Web Technologies- A 2
computer science
m
perspective Jeffrey C. Jackson
o
.c
a
m
a
n
y
d
u
t
S
1

UNIT-02
Hyper Text Markup Language (HTML)
UNIT-02/LECTURE-01
Introduction to Hyper Text Markup Language (HTML)
About HTML: [RGPV/Dec 2013(4)]

m
o
.c
So the first thing is that html the full form is Hyper Text Markup Language. So there are two

a
components to this name. One is hypertext, other is markup. Hypertext is a kind of textual

m
document where you can have links to other documents. In html this kind of links are allowed.

a
So in that sense, html is a hypertext document. Markup, we shall be explaining shortly. This

n
html actually constitutes a collection of platform independent styles. This is called platform

y
independent in the sense that well you can view these files on any browser you want. It can be

d
explorer, it can be konquerer, it can be Mozilla. So in that sense these styles are considered to

u
be platform independent. They are all; they are actually part of some kind of standard. And

t
these styles will define the various components of a web document. And we will actually specify

S
how the document will be displayed on the window of the browser.
Now in html these styles are specified by something called markup tags. This we shall be
explaining very shortly. So html essentially is a plain text document. It can be opened and edited
using any simple text editor. You can use any simple text editor like notepad, like vi and you can
view the doc. You can view the source file of the html you can edit it. But of course there are
many more sophisticated editors which are available, these are called what you see is what you
get or wysiwyg editors. These are more graphic user friendly interface oriented where whatever
you type you see it on the screen in exactly the same form in which it will get displayed on the
browser window. In contrast in a text editor you see simple text and those special commands to
specify the styles which when you are viewing on the browser window will show up in a
2

particular way depending on what kind of commands you have put in there.
What is markup language?

Now talking about mark up, well, html is a markup language. Markup language is one where you
have the document or the textual information. In addition you can embed some special
commands in the document, these are called tags. These tags are nothing but some special
formatting commands. Well the idea is that you have some kind of a document with you. You

m
have a document and you can specify some special tags which will tell you, for example, this

o
portion of the document will be displayed in bold face letters and so on. So the mark up tags or

.c
the markup language features will allow you to embed these kinds of special commands in the

a
original html document. These tags essentially specify how the text should be displayed when

m
you are seeing it on the browser or printed when you are taking a print out. So as I told you

a
html is a markup language, it provides some special formatting codes.

n
Again I am repeating, these are called tags in html. Using these tags you can do a number of

y
different things. For instance, you can adjust the fonts in terms of font sizes, font styles, font

d
color; you can create different kinds of lists. You can create font forms, you can include images

u
you can create tables and you can do a lot of other things. So this tags which are there in html

t
provides a very powerful feature that allows you to specify a number of different things with

S
respect to the language. So now there are few things you need to remember. Now in html this
set of this tags are fixed or well defined; which means html is a fixed language. Now we shall see
later, there is a trend where people are talking about. Well a not a fixed language but rather a
language where we can have some extendable or user definable tags. They will be much more
powerful or flexible.
3

HTML tags : [RGPV/Dec 2013(4)]

Now let us see how html tags look like. Now in html, tags are specified by enclosing them within
left and right angle brackets. There are two classes of tags in general. One in which tags appear
in pairs; for example, this is one example. This specifies the beginning of the tag; this specifies

m
the end of the tag. It is like begin-end structure in a document. In this specific example this

o
angular bracket i means that text which is there in between should be displayed in italics font.

.c
And the end tag will contain the same name but it will start with a slash character. So remember
the slash character before the name of the tag will specify that the tag definition is ending here.
a
So in text you can have a begin tag and end tag and whatever comes in between will get
formatted as part of the definition of that tag.
m
a
n
But there are some tags for this end tag is not required for the tag definition appears

y
individually. This is an example. This img is the name of a tag. This is the begin tag symbol. This

d
is the ending angular bracket and between these examples also illustrates that in addition to the

u
tag name img you can have some attributes specified like here. This example tells you that you

t
want to include an image whose, the corresponding file name is baby.jpg. So here src is an

S
attribute which specifies which is the file name for this image. For this you do not need an end
tag with which will contain slash img. Browsers have the capability to interpret the tags so as to
display them in a properly formatted form on the window of the browser.

Some Points:
4

Some points to note is that number one is that most of the tags we use belong to the first
category in the sense that it starts with a tag name it finishes with an end tag. But there is a
slash character in the beginning and in between there is something. This is can be a text this can
be a table whatever which will get formatted according to which tag you are specifying. There is
another point. Tags are not case sensitive. They are case insensitive. So it is up to you how do

m
you want to put in your tag. You can put it in all capital you can put only the first letter capital all

o
lower case or any order of lower and upper case letters you can use. Tags can be nested just like

.c
you can nest structures in a program. This is one simple example. This is a tag html, this is begin

a
html, this is end html. Now within this begin and end there is a begin head, end head, begin
body, end body.

m
So the rules of nesting are identical to the rules of nesting of loops in a conventional

a
programming language. Nesting should be total there should not be any overlap with respect to

n
two different structures. Because, if you have given a begin command the end tag, command

y
should come after any other begin and end tag command you have put inside it, it cannot

d
overlap. And suppose in a browser you are viewing a page, if you want to look at the

u
corresponding html code, most browsers have a view source option which if you click, then the

t
source or the html version of the page gets displayed on a separate window. You can see the

S
html version of the page which has led to the page which you are seeing in form which is getting
displayed.

Well in html you can add as many extra spaces as you want to make your document readable.
5

Browsers will ignore all extra spaces it will ignore all carriage returns. You can put as many lines
of space in between as you want. But browser will take minimum amount of space. It will ignore
all spaces unless you explicitly specify that here is a line break here is a paragraph break and so
on. It will ignore all line breaks. This is done primarily because you know that a browser when it
is displaying on your computer screen. You can resize the browser; you can make it big; you can
make it small. Now depending on the current area of the display window the browser has to
reformat the text or whatever as you display within that space.

So if you are hath coding space in your document it becomes difficult for the browser to format
it. So spacing is the responsibility of the browser how the spacing in the document will be
controlled. So as I have just told spacing is done explicitly done by putting in the paragraph or
the line break commands as part of some tags explicitly. So implicitly by putting extra spaces or
m
extra blank lines browser will not give the additional spacing in between whatever is displayed.
o
.c
But as it is said, it is always good practice to use paces to improve the readability of your html
source code.

a
m
a
n
y
d
u
Some tags as I mentioned, can have one or more attributes. Now each of these attributes have

t
a name. Some of these attributes can also have a value. These attributes specify some

S
additional characteristics of the tag. Some examples are shown here. This first example I have
already mentioned earlier. This img is the tag name. This is the optional attribute. This src is the
name of the attribute. It means that what is the name of the file equal to baby.jpg is the value
of the attribute. Similarly body is another tag where these are the two attributes text and bg
color. Text specifies that what should be the color of the text, that will get displayed and bgcolor
will tell you what should be the color of the background. These are the two things you can
specify. Just instead of specifying color like this. This will just see what this means? This fff and
this 0 0 0? You can also specify colors by specifying names like text equal to white bg color equal
to blue. These are example of attributes of the tags.
6

Now if some tags are unrecognized, for example if you have misspelled a tag, browsers normally
ignore those tags or they will displays just like it were a normal text. It will not do any formatting
with respect to that. It depends on the browser exactly what it does. You can include comments
lines which will be ignored by the browser. When it gets displayed and comment lines begin
with this angular bracket exclamation and three dash. And it will end with three dash followed

m
by closing angular bracket. So comments can lye entirely on a single line or it can be broken

o
across as many lines as you want. So it will be starting with this. It will be finishing with this. So

.c
it is good practice to include comments in html source as to increase the readability, what you
have done in the different sections of the document

a
S.NO RGPV QUESTION m YEAR MARKS
Q.1 a
Describe the structure of an Dec.2013 4
HTML document. n
Q.2 y
What is the difference between Dec.2013 4

d
tag and attributes? Explain with

u
an example.
t
S
7

UNIT-02/LECTURE-02
HTML elements

Now talking of the structure of an html document, an html document consists of two major
portions: the head, the body. Now in the head section you specify some information about the

m
document. This we shall see some of the information today and some we shall see later. For

o
example, you can specify what will be the title of the document. The title of the document

.c
typically gets displayed on the top title bar on the browser when the browser window comes

a
the top title bar displays the title of the document. So whatever you specify as title will come on
the top. There is some additional Meta data you can also specify this we shall talk about later.

m
Meta data actually specify some information about the contents.

a
n
Like for example some of the key words that is that your document contains. These are

y
sometimes used by the search engines in order to provide indexing services. For example if you

d
are searching Google for a page you give a key word that means how to locate the page. So the

u
periodically, Google look for pages, they look for Meta tags in the header. So if they find, they

t
update their data indexing database. In addition to head there is a body. Now in the body
S
portion the actual matter of the document resides and it is the body which gets displayed
within the browser window. The head is something which specifies the title and some other
information. Body is something which gets actually displayed in the window.
8

A simple HTML Document

This is a very small example. This is a very rudimentary and a simple html document. You see
this starts with a begin html, it ends with an end html. Now in most browsers, this begins and
end htmls are optional. This you can also omit. You can see there is a head section, there is a
body section. In the head section you have this begin head and end head. And within the head

m
we have nested only one tag the title tag. Now within the title tag we have specified the title of

o
the document. The name I have given as just the title of the document. Now in the body the

.c
first you have specified in the begin body tag. We have added some attribute, specifying that

a
our text color will be white and our background color will be blue and the actual body of the
document is this. This is the content of the document. This is some text which will come, this is
m
an italic font you see there is a begin italic and an end italic. So the intermediate word is italic,
a
this should come in the italic font. Now this particular html document when it gets displayed on
n
the browser it will look something like this.
y
d
u
t
S
This is the content of the document. This is an italic font. You see that the italic is coming in the
italic font and the background is blue and the foreground is white.
9

Structural HTML tags

So here we first look at the different html tags with respect to their functionality. First we talk
about the tags which define the structure of the document. These are the so called structural
html tags. So first tell us look at this. Structure html tag, the most important one is I told you
html and the html tags they are used to bracket or specify the boundaries of an entire html

m
document. As we have seen in that example, that the first statement in the html file is the begin

o
html. The last statement is the end html. That is the boundary or the beginning or end of the

.c
entire document. This as I mentioned, html tags are optional for most browsers. If you do not

a
specify anything, it will be assumed that html begins and end is present at the beginning and
the end.

m
Well in the html begin html command you can have some attributes. For example, if it is a

a
multilingual document like means you are specifying a document in a different language, other

n
than English. Then using this lang l a n g attribute will specify the language code. This language

y
code can be any international language like for instance bn will mean Bengali, hi will mean Hindi

d
and the default en will mean English. So if a language code is specified then the browser will

u
know which font it has to use to display the document in a proper way. So we are not going into

t
the detail of this multilingual document and processing and display right now. But browsers

S
have a facility or this html language have the facility to specify this kind of language.

Now within html document as it seem you can have a begin head end head tag. This head is
used to provide information about a webpage. There are basically three things which can be
10

nested within head. See head defines a portion of the document begin head and end head.
Now the within or between this begin and end heads you can specify a number of other tags.
Now in fact it is possible to have three different tags base, meta and title. Let us try to see what
these are. Base is a tag where you can specify an attribute, href is equal to you can specify some
URL. Like you have something like this, say you can have base, then you can have href equal to,
you can have docs slash something like this, which will mean is that you are specifying a base
URL out here.
And in the document whatever file name or path name you specify that will with respect to this
base URL you have specified. So in all the documents you need not specify doc slash. Base URL
allows you to have a shortcut in the path name for all subsequent references. If all the
documents you are referencing as part of your html page they can be images, they can be other
documents links to other documents. If they are all located under the same directory structure
m
you can specify, the path in the base and when you actually referring you need not have to
o
.c
specify the whole path every time, just specify the file name which is there within the base URL.
This base URL does not need any end tag.

a
m
a
n
y
d
u
Meta basically provides information about a document. Typically keywords or some description

t
about the document which helps the search engines in indexing the pages so that the pages can

S
be linked with respect to the search engines. Well, use of the title tag we have already seen. The
title tag will specify the title of the document. And the title of the document usually appears on
the title bar on the top; at the top of the browser window. These are the so called structural
tags.
11

And there is another structural tag which is the actual body of the document. So under this
body structure the actual displayable information will be stored or will be specified; the part
which will be actually visible in the browser window. Now within the body part you are actually
bracketing the so called body of the html document. Now in the body part, there are a number
of different attributes you can specify. Well here a couple of this we have already seen. For

m
example we have seen the text attribute, text equal to color. We shall see how we can specify

o
color in different ways. But we can specify a color to the text. If this attribute is present, this will

.c
set the default color for the normal text in the document. So if I write text equal to red, then all
my text will be displayed in the color red in the window unless I explicitly change the color
somewhere else. a
m
a
Similarly bgcolor attribute this also specifies a color. This will set the background color of the

n
document. Background color means the background of the display window will be set to this

y
color. If I specify bgcolor is equal to blue, then my background will become blue. Sometimes we

d
want to or means we like to have an image to be used as a background and not a fixed color. In

u
that case we use the attribute background. Background equal to some URL or path name, this

t
will specify an image file. Background attribute will specify an image file which will be used as

S
tilling background. So in the window that image will come as the background and the text will
be displayed on it. Sometimes we want to have this. Now, in addition to these three attributes,
there are other attributes also.

Well you might be aware that an html document contains links to other documents. There may
be some portions which are clickable if you click on the mouse you go to some other document.
12

These are called hyperlinks. Now you can specify the color of the hyper links the color in which
they will appear. There are actually three parts to it. There is something called alink, simple link
and vlink. Well alink is equal to color means you are setting the color of the active link. Active
link means when you move the mouse on top of a link and click it. What color that link or that
document which points to other document that part of the document what color will it become.
That is active link.
And simple link is normally which color will be used to show the links. Because in a document
normally the links are shown in a different way either underlined or in a different color. So you
know that these are portions which you can click using the mouse. This is the link and vlink says
the links which are already clicked are visited. Normally they are shown by a different color, so
that you remember that these are links that I have already clicked that color also you can
specify. So in general you can specify these three colors as different. One is active link, one is
the normal displayable link and other is the visited link. m
o
How to specify Color?
.c
a
m
a
n
y
d
u
The next is how do I specify colors? Well here although I have given some examples. Let me tell

t
you how you can do this. There are two ways the first way and the most flexible way is to

S
specify the red, green and blue components of the color. Now you may be knowing that red,
green, blue, these are three fundamental colors and that any color in this universe can be
generated by some combination of these three. So in this method we are specifying this red,
green and blue components separately and each of this components are encoded in 8 bits. So in
hexadecimal it can be minimum 00 maximum FF. 00 means the contribution of the color is
minimum it is turned off. FF means the contribution is maximum.

Well, why we specify a color in this way, you do it like this; body text equal to for example this is
a color. The hash sign indicates that you are specifying it in this mode color red, green, blue
mode. This hash also means hexadecimal. The first two characters means red, next two means
13

green, last two means blue. In the first one red is FF, green is FF, blue is also FF, which means
red, green, blue all are maximum combination of which means white. This is how we specify the
white color. Similarly for bgcolor red is 0, green is 0, blue is maximum. So we are specifying a
deep blue color. Well in this way you can specify any kind of color if you know the combination
which combination will result in which color.

m
But there is an easier alternative. Of course there are some limitations to this you cannot

o
arbitrarily specify any color. There is a list of color names you can specify the color by the name.

.c
Some of the colors that all browsers support are these aqua, black, blue, gray, green, lime, and
etcetera. So you can use one of these colors also in this specification. For example you can say
a
body text equal to white, body bgcolor equal to yellow. Well, this example shows you that this

m
begins and end codes are optional. This you can give and you may not give both will be
interpreted correctly by the browser.
a
n
y
Text Formatting in HTML: [RGPV/Dec 2013(6)]

d
u
How we can do text formatting in html? Well in html one of the most important things is to

t
display text. So, let us see how we can display text and how we can do different kinds of

S
formatting using html.
Paragraphs and Headings

First let us talk about paragraphs and headings. Well html allows you to specify headings by
14

using the h tag; begin h, end h, followed by number n. N is a number which can vary from 1 to 6.
So you can have 6 different levels of headings. H1, H2, H3, H4, H5, H6. H1 means the biggest
and the boldest headings. H2 means slightly smaller. H3 is even smaller and so on. H6 will be
the smallest. Well this among this H1 to H6, all of the text which are enclosed in these headings.
They will be displayed in bold or emphasized font. But their sizes will go on progressively
reducing.

So if in a document you have several different levels of headings like a section name subsection,
name sub, sub section name. You can have different classes or levels of headings to specify
which section you are. So as I told you, H1 one is the largest. H6 is the smallest. We shall see
examples later and whatever text you include between, this begin heading and end heading will
get displayed with respect to that heading size. P, this indicates a paragraph break. This tag just
a p within angular brackets is used to separate text into paragraphs. m
o
.c
Well sometimes a paragraph you can enclose by giving a begin paragraph and finishing with an

a
end paragraph. But the end paragraph tag is optional. This you need not always give just you

m
can give a bracket p bracket between paragraphs automatically. Paragraph spacing or break will

a
be taken. But one thing you remember that if you put a number of paragraph breaks one after

n
the other with no intervening text. Then the browser will take only one paragraph break and

y
ignore all the rest. So even if you put a number of different paragraph p p p by one after the

d
other, only space equivalent to a single paragraph break will be taken or considered by the

u
browser.

t
S

BR is a line break. Means this is used to specify that the text which follows should begin on the
next line. Well in a sense, this is similar to paragraph break also but the difference is that, in a
paragraph break, the spacing between the two sections of the document is more. But in a BR
break, there is no extra line spacing. The only thing is that the text which follows that BR will
start from the next line. But there will be no addition spacing between the line. This is the
15

difference between BR and paragraph p. Just an example if you want that these three lines be
displayed on three different lines, on the browser then you give a BR at the end of the first two
lines. This is not a paragraph. Break the lines will be displaying will be displaying with the
normal text spacing. Only the thing is that they will be starting on different lines. Well in many
cases we want that some text begin from a new line. So in that case you can give the BR break
command.

m
o
This HR command produces a horizontal line. Sometimes we need to put a horizontal line like

.c
this in the document. Well this can be used to separate a delimit in the different sections. Now

a
HR is flexible in the sense that the length of the line the width can be specified some example
follows. If you give a simple HR, well this HR does not contain an end tag. This HR means a rule

m
will be displayed across the full width. If you give HR size equal to 20, this 20 will mean the

a
thickness of the line. That is, how thick the line will be that is the width of the line. Now if you

n
give just like this HR size equal to 20, then the line will be displayed as a hollow thick line like

y
this. What if we give additional attribute called no shade after this 20, just a space and no

d
shade. Then this line will be solid.

u
This will come as a solid line. HR width is equal to 75 percent. You can also specify width. Width

t
equal to 75 percent means it will have a width equal to 75 percent of current displayed window.

S
If the window is bigger it will be 75 percent of that if we have resized the window to make it
smaller. The line will be 75 percent of that. So you specify the relative width of the window with
respect to the widow size of this line. And there is another way of specifying the width by
specifying just a number. In this case, this 120 will mean that it is how many pixels the width is
specified in terms of number of the number of dots. And this right is specified that your line will
be right justified. It will be justified right you can just instead of right. You can specify left that
case it will be left justified.
16

Sometimes you need to display the contact information of the author or the person you can use
the address tags for that purpose. One example is shown here between begin address and at
the end address. I can give my contact details. Of course with a line break across lines otherwise
everything will display on the same line. Now if it is given in address normally some spacing is
given at the beginning at the end and they are usually formatted in italics font.

m
Appearance of Text:

o
.c
a
m
a
Now with respect to the appearance of text, there are some tags like when you want to display

n
a text in the bold font you can use the b tag; begin b, end b. So the text everything which is

y
there between the begin b and end b that will get displayed in bold font. Similarly you can

d
display in italics. Italics is I; begin i and end i. Sometimes you want to display some kind of a

u
citation. The browser has a facility to display citation in a particular form. There is begin cite,

t
end cite tag in html for this. But most browser display the cite in italics font only, but with

S
proper spacing. So cite and italic may be the same in some browser. But in some other browser
the cite may be displayed in a different, may be in a different color. So depends on the browser
really.
17

Sometimes you need to display some text which is already preformatted. Well I am giving you
two examples. Suppose I have a program code. But I have already given some comments some
indentations so that my program code already looks good or I have an array of numbers. This
can be table containing some array of information head expenditure income balance etcetera.
So these are available in text form I want that the browser should display this in exactly the
same form I type, I give space in between value type. So there is a tag called pre formatted tag
called pre; in short begin pre, end pre. So whatever you include between the begin pre and end
pre for example in the here we have included a c-program segment.
This c-program segment will get displayed exactly in this format. So this is how it will get
displayed and normally in the preformatted display when it is displayed using the pre tags. The
font size is some kind of uni space or mono space fonts like courier. In the courier font the width
of all characters are equal. This is unlike other fonts like times new roman or Arial which we use
m
more commonly where you have something called proportional spacing. Where an i is thinner
o
.c
than w for example. But in pre whenever it is displayed, it displayed in some kind of a font
where spacing is equal like courier.

a
m
a
n
y
d
u
Sometimes when you want to use a part of the text to be displayed as subscript, you can use

t
the sub tags. Similarly for super script you can use the sup s u p tag. Well sometimes you can

S
specify the style of the enclosed text using the font tag. Now in the font tag there are a number
of attributes. Means after this begin font you can specify the attributes. Now attributes can be
color equal to the name of the color. Face equal to type face. Well, here you have to know the
name of the faces it can be Arial, it can be Courier, it can be Times New Roman etcetera. You
can specify the size of the font also. The size can be specified in two ways. Well the size is a
number from 1 up to 7; 3 is the default.
If you do not specify anything text are displayed in a font size of 3. So using this size you can
specify any number from 1 to 7, 1 will mean a small font size; 7 mean the biggest. But instead of
an absolute number you can also specify the relative number like plus n or minus n. Like you can
specify size equal to plus 2 which means it is 2 steps above the current font size. If the current
18

font size is 3, it will be 5; 2 steps above. So value can be a just a number 3 or it can be plus 2
something like this. So you can specify value in either of these two ways. So if you specify plus
and minus, it will be with respect to some base font. Well there is a tag again to specify the base
font size. So with respect to that you can specify.

Center is a tag which is used to center some text in a document. Begin center, end center
whatever is in between will be displayed centered. Well I have said normally paragraph
spacing does not need an end paragraph. But in some cases where you want to do some
m
paragraph alignment you need to have this end paragraph. Well you can have this align
o
operator. This align attribute, align equal to option. Now option can be either left, right or

.c
center. So you can have a paragraph which is aligned left, justified right justified or it is
centered right.
a
m
a
S.NO RGPV QUESTION YEAR MARKS

n
Q.1 Explain with example various Dec.2013 6

y
text formatting attributes

d
u
t
S
19

UNIT-02/LECTURE-03

XHTML : [RGPV/Jun 2014(7)]


XHTML reformulates the existing HTML technology to be an application of XML. It is already
used for mobile phone and PDA Internet sites, and expected to gain widespread use as XML
becomes more popular. Dan Wellman explains the differences between XHTML and HTML 4,
and shows how easy it is to make the switch.
XHTML was invented to try to clean up the mess left by trying to make HTML a full-fledged

m
presentation tool, and to reduce the fragmentation of HTML caused by the introduction of non-

o
standard elements, mainly by Microsoft and Netscape. Additionally, XML is viewed by many as

.c
the future of the Internet, so reformulating existing markup technology to be an application of
XML is a step towards embracing that future and letting go of the long standing legacy of the

a
past. XHTML is now the specification of choice for mobile phone and PDA Internet sites, so its

m
cross platform functionality is already being taken advantage of in excellent ways.

a
XHTML and its predecessor HTML 4 are extremely similar languages to use. Anyone that has

n
worked with HTML 4 (or XML even) will find switching to XHTML extremely easy; it is more

y
often then not simply learning to break those bad coding habits that many of us have found so

d
easy to slip into. Remembering the few rules that come with XHTML, and trying to avoid any

u
deprecated tags where possible, is all it really takes. In HTML, the mark-up surrounding your

t
content is traditionally referred to as a tag, the <a> tag for example. In XML and subsequently,

S
XHTML, these tags and the text enclosed within them are known as elements. For example:
<p>This sentence, including the opening and closing tags is known as a paragraph element</p>
<p>This is a separate paragraph element</p>
Basic XHTML syntax and semantics
XHTML is a separate language that began as a reformulation of HTML 4.01 using XML 1.0. It
continues to be developed:
XHTML 1.0, published January 26, 2000 as a W3C Recommendation, later revised and
republished August 1, 2002. It offers the same three variations as HTML 4.0 and 4.01,
reformulated in XML, with minor restrictions.
XHTML 1.1, published May 31, 2001 as a W3C Recommendation. It is based on XHTML 1.0
20

Strict, but includes minor changes, can be customized, is reformulated using modules from
Modularization of XHTML, which was published April 10, 2001 as a W3C Recommendation.
XHTML 2.0,. There is no XHTML 2.0 standard. XHTML 2.0 is incompatible with XHTML 1.x and,
therefore, would be more accurate to characterize as an XHTML-inspired new language than an
update to XHTML 1.x.
XHTML 5, which is an update to XHTML 1.x, is being defined alongside HTML 5 in the HTML 5
draft.

Markup:
HTML markup consists of several key components, including elements (and their attributes),
character-based data types, character references and entity references. Another important
component is the document type declaration, which specifies the
m
Document Type Definition. As of HTML 5, no Document Type Definition will need to be
o
.c
specified and will only determine the layout mode.
The Hello world program, a common computer program employed for comparing

a
programming languages, scripting languages and markup languages is made of 9 lines of code

m
although in HTML newlines are optional:

a
<!doctype html>

n
<html>

y
<head>

d
<title>Hello HTML</title> </head>

u
<body>

t
<p>Hello World!</p> </body>
</html>
S
(The text between <html> and </html> describes the web page, and The text between <body>
and </body> is the visible page content.)
This Document Type Declaration is for HTML 5. If the <!doctype html>
declaration is not included, Windows Internet Explorer will render using "quirks mode".
HTML Text Formatting Tags

Tag Description

<b> Defines bold text


21

<big> Defines big text

<em> Defines emphasized text

<i> Defines italic text

<small> Defines small text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<ins> Defines inserted text

<del> Defines deleted text


m
o
.c
HTML "Computer Output" Tags

Tag Description

<code> Defines computer code text


a
m
<kbd> Defines keyboard text
a
<samp>
n
Defines sample computer code

y
d
<tt> Defines teletype text

<var>
u
Defines a variable

<pre> t
Defines preformatted text
S
HTML Citations, Quotations, and Definition Tags

Tag Description

<abbr> Defines an abbreviation

<acronym> Defines an acronym

<address> Defines contact information for the author/owner of a document

<bdo> Defines the text direction


22

<blockquote> Defines a long quotation

<q> Defines a short quotation

<cite> Defines a citation

<dfn> Defines a definition term

Your browser does not support inline frames or is currently configured not to display inline
frames.
RELATIVE URLS:

A URL is another word for a web address.

m
A URL can be composed of words, such as "w3schools.com", or an Internet Protocol (IP)

o
address: 192.68.20.50. Most people enter the name of the website when surfing, because

.c
names are easier to remember than numbers.

URL - Uniform Resource Locator a


m
When you click on a link in an HTML page, an underlying <a> tag points to an address on the

a
world wide web.A Uniform Resource Locator (URL) is used to address a document (or other
data) on the world wide web.
n
y
scheme://host.domain:port/path/filename
Explanation:
d
u
scheme - defines the type of Internet service. The most common type is http host - defines the

t
domain host (the default host for http is www)

S
domain - defines the Internet domain name, like w3schools.com
:port - defines the port number at the host (the default port number for http is 80)
path - defines a path at the server (If omitted, the document must be stored at the root
directory of the web site
filename - defines the name of a document/resource

Common websites start with http://. Pages starting with http:// are not encrypted, so all
information exchanged between your computer and the Internet can be "seen" by hackers.

Secure websites start with https://. The "s" stands for "secure". Here, the information
23

exchanged will be encrypted, making it useless to hackers.

Common URL Schemes


The table below lists some common schemes:
Which pages will the scheme
Scheme Short for.... be used for...
Common web pages starts
with http://. Not encrypted.
Unwise to enter personal
http HyperText Transfer Protocol information in http:// pages
Secure web pages. All
information exchanged are
Secure HyperText Transfer encrypted, cannot be read by
https Protocol hackers
For downloading or

m
uploading files to a website.

o
Useful for domain
ftp File Transfer Protocol maintenance

.c
file A file on your computer

a
gopher A Gopher document or menu
news A newsgroup
Wide Area Information
m A database or document on a

a
WAIS Search WAIS database

n
HTML TABLES
y
d
Tables are defined with the <table> tag.

u
A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the

t
<td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain

S
text, links, images, lists, forms, other tables, etc.
Table Example
<table border="1"> <tr>
<td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr>
<tr>
<td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr>
</table>
How the HTML code above looks in a browser:
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
24

HTML Tables and the Border Attribute


If you do not specify a border attribute, the table will be displayed without borders. Sometimes
this can be useful, but most of the time, we want the borders to show.
To display a table with borders, specify the border attribute:
<table border="1"> <tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td> </tr>
</table>

HTML Table Headers


Header information in a table are defined with the <th> tag.
The text in a th element will be bold and centered. m
<table border="1"> <tr> o
<th>Header 1</th> <th>Header 2</th> </tr>
.c
<tr>
a
m
<td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr>

a
<tr>
<td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr>
</table> n
y
How the HTML code above looks in a browser:
Header 1 d Header 2
u
t
row 1, cell 1 row 1, cell 2

S
row 2, cell 1 row 2, cell 2

HTML LISTS
The most common HTML lists are ordered and unordered lists:
HTML Lists
An ordered list: An unordered list:
1. The first list item List item
2. The second list item List item
3. The third list item List item
25

HTML Unordered Lists


An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>

How the HTML code above looks in a browser:


Coffee
Milk
HTML Ordered Lists
m
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
o
.c
The list items are marked with numbers.
<ol>
<li>Coffee</li>
a
m
<li>Milk</li>

a
</ol>

n
How the HTML code above looks in a browser:

y
1. Coffee

d
2. Milk

u
t
HTML Definition Lists

S
A definition list is a list of items, with a description of each item.
The <dl> tag defines a definition list.
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes
the item in the list):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd> <dt>Milk</dt>
<dd>- white cold drink</dd> </dl>

How the HTML code above looks in a browser:


26

Coffee
- black hot drink
Milk
- white cold drink

Basic Notes - Useful Tips


Tip: Inside a list item you can put text, line breaks, images, links, other lists, etc.
HTML List Tags

Tag Description
<ol> Defines an ordered list

<ul> Defines an unordered list


m
<li> Defines a list item
o
<dl> Defines a definition list
.c
<dt> Defines an item in a definition list
a
<dd> m
Defines a description of an item in a definition list

a
n
HTML FORMS
y
d
HTML forms are used to pass data to a server.

u
A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons

t
and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.

S
The <form> tag is used to create an HTML form:
<form>
.
input elements
.
</form>

HTML Forms - The Input Element


The most important form element is the input element. The input element is used to select user
information.An input element can vary in many ways, depending on the type attribute. An input
27

element can be of type text field, checkbox, password, radio button, submit button, and
more.The most used input types are described below.

Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into:
<form>
First name: <input type="text" name="firstname" /><br /> Last name: <input type="text"
name="lastname" /> </form>

How the HTML code above looks in a browser:

First name:

m
Last name:

o
Note: The form itself is not visible. Also note that the default width of a text field is 20

.c
characters.

Password Field a
<input type="password" /> defines a password field:
m
<form>
a
n
Password: <input type="password" name="pwd" /> </form>

y
How the HTML code above looks in a browser:

Password:
d
u
Note: The characters in a password field are masked (shown as asterisks or circles).

Radio Buttons t
S
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of
a limited number of choices:

<form>

<input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex"
value="female" /> Female </form>

How the HTML code above looks in a browser:


Male
Female

Checkboxes
28

<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE
options of a limited number of choices.

<form>

<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> <input


type="checkbox" name="vehicle" value="Car" /> I have a car </form>

How the HTML code above looks in a browser:


I have a bike
I have a car
Submit Button
<input type="submit" /> defines a submit button.
A submit button is used to send form data to a server. The data is sent to the page specified in
m
the form's action attribute. The file defined in the action attribute usually does something with
o
.c
the received input:
<form name="input" action="html_form_action.asp" method="get"> Username: <input
type="text" name="user" />
a
m
<input type="submit" value="Submit" /> </form>

a
n
How the HTML code above looks in a browser:

y
Username: SUBMIT

d
If you type some characters in the text field above, and click the "Submit" button, the browser

u
will send your input to a page called "html_form_action.asp". The page will show you the

t
received input.

HTML Form Tags


S
Tag Description
<form> Defines an HTML form for user input

<input /> Defines an input control

<textarea> Defines a multi-line text input control

<label> Defines a label for an input element

<fieldset> Defines a border around elements in a form


29

<legend> Defines a caption for a fieldset element

<select> Defines a select list (drop-down list)

<optgroup> Defines a group of related options in a select list

<option> Defines an option in a select list

<button> Defines a push button

HTML FRAMES: [RGPV/Jun 2010(8)]


With frames, you can display more than one HTML document in the same browser window.
Each HTML document is called a frame, and each frame is independent of the others.

m
The disadvantages of using frames are: o
The web developer must keep track of more HTML documents
.c
It is difficult to print the entire page
a
The HTML frameset Element m
a
The frameset element holds two or more frame elements. Each frame element holds a separate

n
document.The frameset element states only HOW MANY columns or rows there will be in the
frameset. y
d
u
t
The HTML frame Element

S
The <frame> tag defines one particular window (frame) within a frameset.In the example below
we have a frameset with two columns.
The first column is set to 25% of the width of the browser window. The second column is set to
75% of the width of the browser window. The document "frame_a.htm" is put into the first
column, and the document "frame_b.htm" is put into the second column:
<frameset cols="25%,75%"> <frame src="frame_a.htm" />
<frame src="frame_b.htm" /> </frameset>

Navigation frame
How to make a navigation frame. The navigation frame contains a list of links with the second
30

frame as the target. The file called "tryhtml_contents.htm" contains three links. The source code
of the links:
<a href ="frame_a.htm" target ="showframe">Frame a</a><br> <a href ="frame_b.htm" target
="showframe">Frame b</a><br> <a href ="frame_c.htm" target ="showframe">Frame c</a>
The second frame will show the linked document.
Jump to a specified section with frame navigation
Two frames. The navigation frame (content.htm) to the left contains a list of links with the
second frame (link.htm) as a target. The second frame shows the linked document. One of the
links in the navigation frame is linked to a specified section in the target file. The HTML code in
the file "content.htm" looks like this: <a href ="link.htm" target ="showframe">Link without
Anchor</a><br><a href ="link.htm#C10" target ="showframe">Link with Anchor</a>.
HTML Frame Tags
m
o
Tag Description

.c
<frameset> Defines a set of frames

<frame /> Defines a sub window (a frame)


a
m
<noframes> Defines a noframe section for browsers that do not handle frames

<iframe>
a
Defines an inline sub window (frame)

n
S.NO y
RGPV QUESTION YEAR MARKS
Q.1 d
Discuss the difference between June.2014 7

u
HTML and XHTML with respect
t
to elements.
Q.2 S
Write a HTML code to create the June.2010 8
following frames. What is a
frameset?
Rajiv Gandhi Praudyogiki
Vishwavidyalaya Bhopal, M.P.
Menu Welcome
 About us
 Scheme
 Result
31

UNIT-02/LECTURE-04
eXtensible Markup Language (XML) : [RGPV/Jun 2011,12(10)]

,
Html is a language using which you can create the web pages. It is a markup language. Markup

m
language means, we specify the textual content of the document. As well as we specify how the
o
textual content should be structured or should be viewed on the screen. The concept of the

.c
tags and attributes come from there. So this is what a markup language is. Now XML like html is

a
also a markup language. So here lies a similarity. Let us see. So XML is also a markup language.

m
Well although here we are talking about creating documents. We shall see later that XML has

a
been used not only for creating document but for many other applications as well. There is

n
some structured information that we can capture through tags like html. Markup language is

y
that, markup language use of tags is a mechanism to identify structure. For example a begin

d
paragraph and end paragraph tag will tell you that, well this is a paragraph in the document.

u
Begin h1 and end h1 will tell you that this is a heading in the document. So these are structure

t
information which you can extract. So structure information will contain content which can be

S
text, which can be other form of information also, image. And also it should contain of what role
the content plays. For example I gave you some examples, heading, paragraph, address. But one
problem with html is that the set of tag is limited by the definition of html. If for example I want
to define a new tag for country, for city, I do not have it. But in XML we can do it. We can define
our own tag we shall see it later.

XML vs. HTML


32

XML and html first thing is that both are markup languages, there are differences as I had
mentioned. This html is a fixed language the tag set and the meanings of the tags are
predefined. They are fixed and you cannot change it. The browsers have been designed
following these rules. Even you cannot change it in the browser you cannot tell the browser that
h2 tag you should display it in italics in color red that we cannot tell the browser. You will have

m
to modify the document itself in order to make this into effect but in contrast XML specifies

o
neither a tag set nor semantics.

.c
XML is a totally open language and totally flexible language it does not specify anything by
default, depending on your application domain your context you will have to define everything

a
and it is entirely up to you can customize XML as you want it to be. So XML provides you the

m
facility to define tags. It can allow you to define semantics which can be defined by applications

a
for example this html means I repeat. Html is meant for creating documents XML is meant for

n
creating some content. This content is not only meant for viewing on the browser.

y
There are a much wider range of applications of xml, as you can see some typical application

d
later. The idea is like this. Whatever you define in XML you can write a program later may be in

u
C, C++, Java, whatever that program can read that document and can process it. So the

t
application there will be of course some application programming interfaces to extract the

S
structure information from the XML specification. And the semantics can be defined by the
application that what a particular tag means that the application can define or can understand.
So XML is therefore more like a meta language it is not a fixed language which defines
everything it is a language using which you can describe markup language. For example using
html you can define html because html has a fixed set of tags you can define all of them in html,
in that means you can define al of them in html and whatever you get is an html
implementation using xml. Similarly using XML you can do a host of other things host lot of
other things.

XML Development Goals


33

But the primary goals of XML if you look at it, you will understand a few things. The first was
that initially it was meant to be used over the internet. So the first goal was it should be easy to
use over the internet. This also means that the browsers you see around us they should
understand xml. There should be some complaints in deed most of the modern browsers can
understand xml. XML shall support a wide variety of application, this is a secondary objective.
This application does not necessarily mean that only viewing the documents on the browser. It
m
o
shall be easy to write programs that process XML documents. These are these applications

.c
which are running using XML specifications. The number of optional features in XML is kept to a
minimum ideally it is zero.

a
See optional feature means if you look at the at the html specification, you will find the some of

m
the specifications were referred to has been mandatory. But some were set to be optional and

a
there was a problem with the optional specifications. Some browsers implemented some

n
optional features, some other browsers implemented some other set of optional features. So if

y
you create a document using the optional features there is no guarantee that can interpret it in

d
a correct way. So if there were no optional features at all there would be no ambiguity. So XML

u
does or aims to just that. Design of XML shall be formal and concise it is so and it should be easy

t
to create. There are many XML document editors available now a days using which you can

S
create XML documents.

How is XML Defined?


34

So let us see how XML is defined. XML is defined broadly using three different specifications or
specification languages whatever you call. The first is the basic XML specification. This is the
extensible markup language version ͞1.0͟. This defines the syntax of xml. The language
constructs how we have to how you need to write the constructs of the language the syntax.
The second thing is there is something called XML pointer language in short x pointer; XML
linking language in short x link. These are still undergoing some refinements. Now this xpointer
and xlink, these are some specifications or languages using which you can create some thing
similar to hyperlinks as you create in html. The standard XML specification does not support
hyperlink.
You have to use xlink specification for that. So this xlink or xpointer this defines standard ways
to represent link between resources and the third one is extensible style language or xsl. This is
something similar to the html style sheet that we were discussing in the last class. Here you can
m
define the standard style sheets and this language specifies how means the exact format and
o
.c
syntax using which you can do that. The advantage of having xsl is obvious. Suppose your main
application is to use the browser for viewing information. Then you will be creating a style sheet

a
xsl specifically for browser related definitions and syntax semantics whatever you call. So how to

m
compose paragraphs headings center different kinds of alignments, fonts, etcetera.

a
n
An Example of XML Document

y
d
u
t
S
A very small example an XML document looks like this. It starts with a beginning line. This is
sometimes called as an XML prolog. This tells you that this is an XML document it begins with
less than question mark followed by the key word xml. Version specifies which version of XML it
is followed by end and inside the XML there can be several tags just like html like quotation,
begin quotation, end quotation, Isay, end isay, yousay, end yousay. See these tags look very
peculiar it is indeed peculiar. They were not part of the definition I have defined it according to
my need. This particular example I have taken may be it is a portion on except from a dialogue
that is going on between two persons myself and you. See whenever I am enclosing some text
35

between the tag isay. This is means I am telling you something between yousay means you are
telling something. There can be a large number of alternates of isay and yousay in the total
document that will constitute the whole conversation
But I am calling quotation, you can call it something else also. In xml in some cases you may
have a pair of tags with nothing in between it is called an empty tag. There is a way to specify an
empty tag it is like this the name of the tag followed by slash. This is of course equivalent to
begin frown end frown. So instead of writing this frown twice. I can simply write frown followed
by slash. This will mean that it is the frown tag but it is presently empty nothing is there in
between. So this gives an idea about what or how means html document will look like there are
some tags. Well I had used some tags according to my need and I can understand what the
meaning of this tags are but may be you will not understand. So the tags will be defined
depending on the application which will be processing it or the person who will be viewing it or
looking at it. This is the basic idea. m
o
Structure of XML Document: [RGPV/Dec 2013(5)]
.c
a
m
a
n
y
d
u
So talking about the structure of a XML document there are 5 different components of the

t
document. Prologs, elements, attribute, entity references and comments. Let us see what
these are. S
XML Prolog

First is prolog. Prolog as I said with the help of that example. That is the beginning you need to
36

specify that this an XML document that is the prolog. It is the beginning or starting of the
document that tells you the prolog has to be the first structural element that is present. First
structural element means before that you can have comments. Comments are just like html, so
there is no confusion. There you can have blank lines. But the firststructural element will be the
prolog. Prolog is sometimes divided into an XML declaration and an optional so called data type
declaration that we shall see later.
Some typical examples of prolog definition are this. The second version we have already seen
earlier the first version has an optional tag. This is the DTD I have said. This specifies some
encoding rules. This is an XML file version ͞1.0͟ it uses some encoding rules UTF8. UTF8 is a
standard encoding rule where some special character can be encoded by some special escape
sequences and the like. So that when you are processing it, just looking at the prolog you will
understand that what kind of special characters and their encodings you are likely to encounter
in the document m
o
XML Elements: : [RGPV/Dec 2010(10)]
.c
a
m
a
n
y
d
u
t
These XML elements are like tags. So XML elements they are the most important form of

S
markup or the way of specifying some sections of the document or text whatever you are
correct, you are doing or writing. Now XML elements when you are using, they must contain a
start tag and a matching end tag just like html. You can say that in html the elements were
predefined and you are calling them tags so begin tag end tag there are ways of doing it. End tag
starts with a slash with the same name. So here also that syntax remains the same. A small
example an element we are calling it city end element slash city in between some text.
Well this text can be arbitrary, but in the context of XML we understand that this Kharagpur is a
name of a city. Some application which is reading the data will understand that this Kharagpur is
part of an element called city. So the application understands that this is a name of a city. So
semantic is also captured here very nicely. And as I mentioned in that example, that if you have
37

empty elements you can write them by putting a slash after the name of the element. Well here
alternatively you can also use both the tags without any content in between blank and one
thing to note is that unlike html XML is case sensitive. So when you are defining an element city
lower case c i t y and capital C I T Y are not the same.
You must follow the same case convention when you are using xml. When you are just using
XML for some other applications. There is a naming convention for the element. That means
when you define for example I have given the name city. So how you can define names? There
are some simple rules. Rule says, that the name must begin with an underscore or a letter.
Letter means a correct a to z. But within the name you can have any number of letters, digits,
underscore, hyphen and dots or periods. So any combination of this will constitute the name of
the element. So it is an element you can construct using any combination of these.

XML Attributes m
o
.c
a
m
a
n
There is something called attributes, this attributes are also quite similar to what is there in
y
html. In html we had tags; along with tags we had attributes. Whenever we have the begin tag
d
along with the begin tag we specify the attributes. Here also we do something very similar the
u
t
syntax is very similar here also. Here the tags are called elements. So we say that attributes are

S
associated with elements. So XML attributes are attached to elements they are mostly name
and value pairs that occur inside start tags like html after the element name. What I mean is
that something like this. Suppose in this example we have defined an element whose name is
faculty.
And in this start faculty tag element you can say I have defined an attribute. The name of the
attribute is n a m e name and indranil sen gupta is the value of that attribute. And within this I
can have anything. For example here the body contains the email address but it can contain
anything. So name value pairs will constitute attributes. So this simple example shows that we
have associated one attribute with this element faculty. Must begin with a letter or underscore.
The attribute name must not begin with anything else.
38

This is the constraint and must not contain any white spaces. You cannot give any blank in
between. This equal to before and after should not be any blank

XML Entity Reference

Well entity references, see entity references actually mean that when you are creating a

m
document you define some tags. Tags normally use less than greater than for defining tags. So

o
use some of the symbols that are available in your alphabet that are available in the key board

.c
to define something special. Now if in the document those same symbols are appearing you
normally use some kind of escape sequence to indicate that well this is that particular character

a
not the starting of a tag less than for example. So the entity references as it is mentioned under

m
XML actually talks about exactly that. They are used to reference data that are not directly in
the struct.
a
n
Not directly in the structure means you cannot normally use those data or those symbols in the

y
structure because they mean something else. But in order to use that you will have to do

d
something else. So there are two things. This can be internal, this can be external. There are two

u
ways of doing it. So internal means the entity references whatever you do; that will define as

t
part of the same file and external as the name implies this will be in some other fact. But in

S
addition to internal external there are other ways of mentioning. We will see it through
examples later. Built in entity reference something internal external there is something builtin.
This is already there.
Built-in means these are some special symbols which we use in XML ampersand, less than,
greater than, quotation, double quote and apostrophe, single quote. So a small example
follows. Suppose I have a string like this Tom and Jerry bracket quotation do not. There is an
apostrophe in between. Write x less than y quote bracket closed. Now if you write a string like
this, this ampersand double quote single quote less than, this will totally confuse the XML
parser or processor because they some other meaning to xml. So you will have to escape out
this using special escape sequences and specify it in a slightly different way. The same text you
39

will be writing like this.


Instead of this ampersand symbol you will be writing ampersand amp semi colon. This
ampersand is the escape sequence here all special symbols will start with ampersand then some
name small short name followed by a semicolon. So ampersand amp semi colon is this jerry
then this quotation comes double quote. This is ampersand quote ampersand semicolon. Don, d
o n then the single quote comes this is ampersand apostrophe semi colon. Write x less than y
less than is again lt double quote at the end this is quote. So in this way where ever there is a
special symbol that you replace by an escape sequence which starts with ampersand followed
by some short name for that particular symbol followed by a semi colon. This is the XML builtin
entity reference.

m
o
.c
a
m
Now there is a special form of entity reference also which you can use. This is called a so called

a
character reference. Now using character reference, you can insert arbitrary characters in the

n
documents. See you know this Unicode is a 16 bit character code which can be used to virtually

y
represent any character in any language. So this allows you to insert arbitrary Unicode

d
characters in the document. Well I am giving a small example. How to do that? You can specify

u
the character code in either decimal or in hexadecimal. In decimal you do it in this way. It as
t
usual starts with ampersand.
S
This hash symbol indicates that this is a character reference followed by 8478 means the
corresponding decimal equivalent of the Unicode 16 bit number; followed by semicolon.
Hexadecimal is similar, only you use a x before the hexadecimal number. Ampersand hash x 211
E. These two actually means the same number and this refers to the prescription symbol which
the doctors give on the prescription that r a small x. That r x is a special symbol that has Unicode
number 8478 in decimal. So this is just an example which shows that if you give this r this
means 8478, actually this prescription symbol will appear on the browser if you are viewing it
on the browser screen.
40

S.NO RGPV QUESTION YEAR MARKS


Q.1 What is XML? What are the June.2012 10
differences between XML and
HTML
Q.2 Explain Extensible Markup June.2011 10
Language(XML).
Q.3 What are the components of an Dec.2013 5
XML file?
Q.4 Explain XML elements and Dec.2010 10
attributes

m
o
.c
a
m
a
n
y
d
u
t
S
41

UNIT-02/LECTURE-05
DTD files : [RGPV/Jun 2012(10),2014(7)]

Document Type Declaration

document type declarations or DTD. Say XML as though as though it may seem that through
element declarations it allows us to create our own tag names. Document type declarations
m
allow a document to send Meta information to the parser about it contents. Meta information
o
means that you send some semantic information to the parser that well these are the tags and

.c
this is the meaning of the tag. This how you should interpret the tag this kind of Meta

a
information can also be sent. Like I am giving a simple example, you think of a browser.

m
Browser is a one very classic example of an XML application an application that is using XML

a
specification. A web page written in XML that is been downloaded the browser tries to display

n
it browser is now an application.

y
So browser is using an XML parser to extract some important information from the XML

d
specification and try to display them in a proper way. Now DTD document type declarations

u
are very useful without the document type declaration the browser will not know that. How to

t
display this particular item on the screen bold centered underlined or how DTDs are important

S
due to this. It also tells you that if there is any important sequencing and ordering of the tags.
This also may be mentioned that tags must appear in this particular sequence. You cannot
have any arbitrary usage of tags. Now broadly four kinds of declarations are there in XML right
you can define elements, you can define attributes as a set of elements, you define something
called entities and notations. These are the four different kinds of definitions that we
encounter in XML specifications.

Element Type Declaration:


42

Let us see first is element type declaration. They identify the names of the elements and the
nature of the content earlier we had seen what an element is and how you can use an element
in a XML document. Let that city Kharagpur end city that was one example. Now here you see
how you can define an element and XML document. Elements identified in names of the
elements and the nature of the content. So I told you in XML there is no predefined element or

m
tag everything I need. I will have to define myself. So this is a way of defining, so elements can

o
contain simple predefined data types they can refer to other elements. They can also be

.c
defined with respect to their cardinality. Cardinality means how many times the element
appears in the XML document.
a
m
Because I may say that a particular document city should not appear in the document more

a
than twenty times or it is unbounded. It can appear any number of times. These kinds of

n
specifications I can also mention through a small example. This defines an element whose

y
name is faculty. Xsd colon element is the keyword used to define elements. Name equal to the

d
name of the element you are trying to define, then type there are several predefined types

u
under xsd again. Xsd colon string means, it is a string. Max occurs is another attribute which

t
says that it is an unbounded that means that there are no limit to the number of times. The

S
faculty element can appear in my XML document. So this way you can define the elements.

Attribute List Declaration


43

Next come attributes. How to define attributes associated with the elements. Like elements
attributes must have a name and type. Attributes can use custom data type also they can also
be restricted with respect to cardinality. As I had mentioned before and also some default
values you can specify they can also refer to other attribute definitions. Like one small example
follows here. Xsd attribute this keyword tells you that you are trying to define an attribute the
name of the attribute is city. Type is again string fixed Kharagpur means this is a default value
and these are restricted value cannot change it. But if you do not give this then anyone can use
any kind of city by default. For example you are you are creating an XML document that is
keeping track of all the bank branches in Kharagpur. So for them the city will always be
Kharagpur you can define them as fixed type, fixed equal to Kharagpur for them this kind of
declarations are relevant.
Entity Declaration
m
o
.c
a
m
a
Entity. Entity will allow us to associate a name with some other fragment or content. Like we

n
have already seen internal entities. Like you are replacing some special characters by their

y
escape sequences. This is one example of entity. That means it is like a macro substitution you

d
have something to replace it with to something else. And later on when you again need it back

u
you replace it back. It is like a macro substitution and d substitution. This is sometimes called
t
S
an entity with which some string or something else is associated you replace the entity by that
string. Essentially it means the same thing, it is like a macro substitution. You have a symbol or
a string you are replacing it with by some other string. These are internal entities which you
can define as part of the xml.
44

External entities are those which associates a name with the contents of another file. This is
also like a macro. But you replace it with something which is not there in your XML file that has
to be brought from somewhere else. So that somewhere else, once you fetch it the contents of
that will be inserted at the point of reference. There is one simple example I am giving. Here I
am defining an entity. Entity IIT logo, this is the name of the entity I am giving. I am saying
system is a keyword followed by a link which tells you where this logo is found this is the URL.
This is actually a URL institute slash logo.gif. So now in my XML wherever I use this IIT logo
entity that will get replaced by that gif file gif image. These are very convenient way of
replacement and this external entity will allow you to do it from other file not from the same
document.
Including a DTD
m
o
.c
a
m
a
n
y
Sometimes we may want to include a document type description definition along with an XML

d
document. There is a way to do this first is that in the prolog you specify that this is not a

u
standalone document. Stand-alone equal to yes is the default. You say that this document

t
depends on some other document for proper interpretation. So this is not a standalone

S
document. So standalone you say no and here you specify the corresponding document type
definition DTD. This is the way to specify this doctype chapter system this mybook.dtd is the
file where all the description of elements and attributes are present. So all the definition you
have put there in one place in a separate file and in this XML file you are including them
instead of repeating the definition every time in every XML you can simply include them as a
DTD. So this is the syntax and after this your chapter type gets defined just like a document
type. This is a document type of chapter. So now we start with begin chapter, end chapter, in
between whatever tags you have defined you can use them in between. This is just an
indication of how you can use a DTD.
45

Validity of XML Document

Now XML documents can be categorized as well formed. If it obeys all the syntax of html of
XML and if it obeys the syntax it can be parsed. You can have another level of you can say well
form ness you can say valid. Valid says it is it will be formed no doubt. But it will also contain a
proper DTD and the document follows all the constraints of the DTD. So it is something more

m
just the syntax. Some semantic is also included then you call it a valid document.

o
.c
S.NO RGPV QUESTION YEAR MARKS
Q.1 What is DTD? Why do we use it June.2014 7
with XML documents? Explain
a
the different components of
m
DTD with example.
a
Q.2
n
What is XML DTD (Document June.2012 10

y
Type Definition)? What is the

d
advantage of having a DTD for

u
an XML document?

t
S
46

UNIT-02/LECTURE-06
Basics of Cascading Style Sheet (CSS) : [RGPV/Jun 2012(10), Jun 2013(20)]
Introduction to Cascading Style Sheets
Cascading Style Sheets (CSS) is a slightly misleading term, since a website might have only one
CSS file (style sheet), or the CSS might be embedded within an HTML file. It is better to think of
CSS as a technology (in the singular). CSS is comprised of statements that control the styling of
HTML documents. Simply put, an HTML document should convey content. A CSS document
should control the styling of that content.
<div align="center"></div> <img src="this.gif" border="0" alt="" /> <table height="200">... <td
width="30"></td>
All these examples can easily be replaced with CSS. Don't worry if you don't understand these
declarations yet.
m
o
div {text-align: center;} img {border: 0 none;} table {height: 200px;} td {width: 30px;}

.c
An HTML file points to one or more external style sheets (or in some cases a list of declarations
embedded within the head of the HTML file) which then controls the style of the HTML
document. These style declarations are called CSS rules.
a
m
a
Features

n
The latest version of Cascade Style Sheets, CSS 3, was developed to make Web design easier but

y
it became a hot topic for a while because not all browsers supported it. However, trends change

d
quickly in technology and all browser makers currently are implementing complete CSS 3

u
support. Making that process easier for the browser manufacturers is CSS 3's modularized

t
specification, which allows them to provide support for modules incrementally without having

S
to perform major refactoring of the browsers' codebases. The modularization concept not only
makes the process of approving individual CSS 3 modules easier and faster, but it also makes
documenting the spec easier.
Eventually, CSS 3 -- along with HTML5 -- are going to be the future of the web. You should begin
making your Web pages compatible with these latest specifications. In this article, I explore 10
of the exciting new features in CSS 3, which is going to change the way developers who used
CSS2 build websites.Some of the features are:
o CSS Text Shadow
o CSS Selectors
o CSS Rounded Corners
47

o CSS Border Image

Core Syntax
1 At-Rules
As we learned when we studied CSS statements, there are two types of statements. The most
common is the rule-sets statement, and the other is the at-rules statement. As opposed to rule
sets, at-rules statements consist of three things: the at-keyword, @, an identifier, and a
declaration. This declaration is defined as all content contained within a set of curly braces, or
by all content up until the next semicolon.
@import
Perhaps the most commonly used of the at-rules, @import, is used to import an external style
sheet into a document. It can be used to replace the LINK element, and serves the same
m
function, except that imported style sheets have a lower weight (due to having less proximity)
o
.c
than linked style sheets.
<style type="text/css" media="screen"> @import url(imported.css); </style>
@import url(addonstyles.css); @import "addonstyles.css";
a
m
Relative and absolute URLs are allowed, but only one is allowed per instance of @import. One

a
or more comma-separated target media may be used here.

n
@charset

y
@charset is used to specify the character encoding of a document, and must appear no more

d
than once. It must be the very first declaration in the external style sheet, and cannot appear in

u
embedded style sheets. @charset is used by XML documents to define a character set.

t
@charset "utf-8";
@namespace
S
The @namespace rule allows the declaration of a namespace prefix to be used by selectors in a
style sheet. If the optional namespace prefix is omitted, then the URL provided becomes the
default namespace. Any @namespace rules in a style sheet must come after all @import and
@charset at-rules, and come before all CSS rule-sets.
@namespace foo url("http://www.example.com/");
@namespace can be used together with the new CSS3 selectors (see below). It defines which
XML namespace to use in the CSS. If the XML document doesn't have matching XML namespace
information, the CSS is ignored.
@font-face
48

This was removed from the CSS2.1 specification, but is still used to describe a font face for a
document..
@font-face { font-family: "Scarborough Light"; src: url("http://www.font.com/scarborough-lt"); }
@font-face { font-family: Santiago; src: local ("Santiago"),
url("http://www.font.com/santiago.tt"), format("truetype"); unicode-range: U+??,U+100-220;
font-size: all; font-family: sans-serif; }
@media
This at-rule is used within a style sheet to target specific media. For example, after defining how
an element is to be displayed (in this example for the screen), the declaration can be
overwritten for print, in which case we often want to hide navigation.
p {font-size: 0.8em;} /* for the screen */ @media print { p {font-size: 10pt;} #nav, #footer
{display: none;} } @media screen, handheld { p {font-size: 14px; text-align: justify;} }
@page m
o
.c
This at-rules declaration is used to define rules for page sizing and orientation rules for printing.
@page {size: 15cm 20cm; margin: 3cm; marks: cross;}

a
You may specify how pages will format if they are first, on the left-hand side, or on the right.

m
@page :first {margin-top: 12cm;} @page :left {margin-left: 4.5cm;} @page :right {margin-right:

a
7cm;}

n
@fontdef

y
This is an old Netscape-specific at-rule which we should ignore.

d
u
CSS1 Selectors

t
S

Selectors refer to elements in an HTML document tree. Using CSS, they are pattern-matched in
order to apply styles to those elements. A selector consists of one or more elements, classes, or
IDs, and may also contain pseudo-elements and/or pseudo-classes.
49

Type Selector
The type selector is the simplest selector of all, and matches all occurrences of an element. In
this example, all <p> tags throughout the document will have the following style applied, unless
overridden.
p {color: #666;}
Universal Selector
The universal selector, used alone, matches all elements in the document tree, and thus will
apply styles to all elements. It is in effect a wildcard.
* {margin: 0; padding: 0;}
In this example, all tags are reset to have no padding or margin. This, by the way, is a practice to
gain control over all the default padding and margin inherent in the way User Agents (UAs)
display HTML.
m
o
.c
Class Selector
The class selector matches a classname.

a
.largeFont {font-size: 1.5em;} h3.cartHeader {text-align: center;}

m
The "largeFont" class will apply to all elements into which it is called. The "cartHeader" class will

a
only function as styled if called into an H3 element. This is useful if you have another

n
"cartHeader" declaration that you wish to override in the context of an H3 element, or if you

y
wish to enforce the placement of this class.

d
u
ID Selector

t
The ID selector matches an ID. IDs are identifiers unique to a page. They bear a resemblance to

S
classes, but are used a bit differently. IDs will be treated more fully below. The first two ID
examples below refer to sections of a web page, while the last refers to a specific occurrence of
an item, say, an image in a DHTML menu. IDs have a higher specificity than classes.
#header {height: 100px;} #footer {color: #F00;} #xyz123 {font-size: 9px;}

Descendant Selector
A selector can itself be a chain of one or more selectors, and is thus sometimes called a
compound selector. The descendant selector is the only compound selector in CSS1, and
consists of two or more selectors and one or more white space combinators. In the example
below, the white space between the H1 and EM elements is the descendant combinator. In
50

other words, white space conveys a hierarchy. (If a comma were to have intervened instead, it
would mean that we were styling H1 and EM elements alike.) Selectors using combinators are
used for more precise drill-down to specific points within the document tree. In this example
<em> tags will have the color red applied to them if they are within an <h1> tag.
h1 em {color: #F00;}
Note that EM elements do not have to be immediately inside an H1 heading, that is, they do not
have to be children, but merely descendants of their ancestor. The previous style would apply to
an EM element in either of the following statements.
<h1>This is a <em>main</em> heading</h1> <h1>This is <strong>another <em>main</em>
heading</strong></h1>
In the next example, the color black will be applied to all <span> tags that are descendants
(whether directly or not) of <div> tags which are in turn descendants (whether directly or not)
of <p> tags, no matter how deep the <p> tags are in the document tree. m
o
.c
div p span {color: #000;}
That is to say, this style would apply to SPAN elements inside a P element, even if they are many

a
levels below (that is, within) the DIV element, as long as there is an intervening P element.

m
The universal selector can be part of a compound selector in tandem with a combinator.

a
p * span {font-size: 0.6em;}

n
This would style any SPAN element that is at least a grandchild of a P element. The SPAN

y
element could in fact be much deeper, but it will not be styled by this declaration if it is the child

d
(direct descendant) of a P element.

u
t
Other Selectors

S
Other combinators convey greater precision. They include the direct adjacent sibling
combinator (+), the indirect adjacent sibling (or general) combinator (~), and the child
combinator (>). These combinators will be treated below because they are part of the CSS2.1
specification, and are not supported in IE6.
EXAMPLE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<head>
<style type="text/css"> div.ex
{
51

width:220px;
padding:10px; border:5px solid gray;
margin:0px;
}
</style>
</head>

S.NO RGPV QUESTION YEAR MARKS


Q.1 What do you understand by June.2012 10
͚style͛? What are the benefits
of using styles compared with
placing formatting directly into
m
the text of webpage? State the
o
.c
different styles which can be

a
applied to HTML document.

m
a
n
y
d
u
t
S
52

UNIT-02/LECTURE-07
How to specify rules of Cascading Style Sheet: [RGPV/Dec 2010(10),Jun 2011(10)]

Some examples see h2 is a standard tag for heading; second level heading. But you can within
curly bracket you can specify like this with in bracket color colon blue. This means I am

m
specifying some rule for the h2 tag. Similarly for paragraph p, I can specify font size 12, font

o
family verdana sans serif, I can specify. So subsequently if I use the p tag; paragraph tag and text

.c
in the paragraph tag would be composed according to these rules. So this is how we can specify

a
rules in html which is beyond the definition of you can say the default definition of html.

m
a
Inline Style Sheet

n
y
d
u
t
S
There is some called inline styles which you can define as part of the html document as this
example shows. This is the header. In the begin header using the style attribute you can specify
color colon blue. So this heading will be appearing blue. Similarly for paragraph you can specify
by style. Again the exact font in which you want this paragraph to appear. So it will appear like
this. Since this is part of the same document same form you call it inline.
Embedded Style Sheet
53

The embedded style sheets are also possible. Embedded style sheet means you have a begin
style end style tag. So you give some name or some type to this style. This is a text cascaded
style sheet type and this is a special marker. This is the beginning and this is the ending and
within this you can define all the styles you want to define. The advantage of this style of
m
definition is that all the definitions you can put in one place. Not only in one place; you can even
o
.c
store in some other file. You can import that file from a main html file.

a
m
a
n
y
d
So after this when you have the main file. You can use those h2; those p, this tag, as part of your
document.
u
t
External Style Sheet

S
54

An external style sheet as I said, this is exactly what I told you that we can define all this style
together and store it somewhere else in some other file. This is external style sheet. You collect
all the styles in a separate document and you create links to that document. There is a link tag
using which you can link a style sheet. So you can specify in which file this style sheet is
mentioned of course type is text CSS. These are some optional parameters you can give but this
is how you can specify. Once you give at the beginning so after that you can give your html
document and description after that.

S.NO RGPV QUESTION YEAR MARKS

m
Q.1 What is the use of CSS in June.2013 20

o
DHTML? Explain the methods

.c
of using CSS with HTML. Write
a suitable program to
demonstrate.
a
Q.2 Define Cascading Style
m Dec.2010 10

a
Sheet(CSS)

n
Q.3 Explain Extensible Markup June.2011 10

y
Language (XML). Also explain

d
cascading style sheet(CSS)

u
t
S
55

UNIT-02/LECTURE-08
Document object Model (DOM):[RGPV/Jun 2014(14)]
INTRODUCTION TO THE DOCUMENT OBJECT MODEL
The Document Object Model (DOM) is the model that describes how all elements in an HTML
page, like input fields, images, paragraphs etc., are related to the topmost structure: the
document itself. By calling the element by its proper DOM name, we can influence it.The
Document Object Model, or DOM, is the interface that allows you to programmatically access
and manipulate the contents of a web page (or document). It provides a structured, object-
oriented representation of the individual elements and content in a page with methods for
retrieving and setting the properties of those objects. It also provides methods for adding and
removing such objects, allowing you to create dynamic content.The DOM also provides an
interface for dealing with events, allowing you to capture and respond to user or browser
m
o
actions. This feature is briefly covered here but the details are saved for another article. For this

.c
one, the discussion will be on the DOM representation of a document and the methods it
provides to access those objects.

a
m
Nodes

a
The DOM is a Document Object Model, a model of how the various objects of a document are

n
related to each other. In the Level 1 DOM, each object, whatever it may be exactly, is a Node. So

y
if you do

d
<P>This is a paragraph</P>

u
you have created two nodes: an element P and a text node with content 'This is a paragraph'.

t
The text node is inside the element, so it is considered a child node of the element. Conversely,

S
the element is considered the parent node of the text node.
<P> <-- element node
|
|
This is a paragraph <-- text node
If you do
<P>This is a <B>paragraph</B></P>
the element node P has two children, one of which has a child of its own:

<P>
56

|
------------------
| |
This is a <B>
|
|
paragraph

Finally there are attribute nodes. (Confusingly, they are not counted as children of an element
node. In fact, while writing this pages I've done a few tests that seem to indicate that Explorer 5
on Windows doesn't see attributes as nodes at all.) So

<P ALIGN="right">This is a <B>paragraph</B></P> m


o
would give something like
.c
a
m
<P> ----------------

a
| |

n
-------------- ALIGN

y
| | |

d
This is a <B> |

u
| right

t
|
paragraph
S
So these are element nodes, text nodes and attribute nodes. They constitute about 99% of the
content of an HTML page and you'll usually busy yourself with manipulating them. There are
more kinds of nodes, but I skip them for the moment.
As you'll understand, the element node P also has its own parent, this is usually the document,
sometimes another element like a DIV. So the whole HTML document can be seen as a tree
consisting of a lot of nodes, most of them having child nodes (and these, too, can have
children).
57

<BODY>
|
|-------------------------------------
| |
<P> ---------------- lots more nodes
| |
-------------- ALIGN
| | |
This is a <B> |
| right
|
paragraph
m
o
.c
Walking through the DOM tree:[RGPV/Jun 2010(4)]
Knowing the exact structure of the DOM tree, you can walk through it in search of the element

a
you want to influence. For instance, assume the element node P has been stored in the variable

m
x (later on I'll explain how you do this). Then if we want to access the BODY we do

a
x.parentNode

n
We take the parent node of x and do something with it. To reach the B node:

y
x.childNodes[1]

d
childNodes is an array that contains all children of the node x. Of course numbering starts at

u
zero, so childNodes[0] is the text node 'This is a' and childNodes[1] is the element node B.

t
Two special cases: x.firstChild accesses the first child of x (the text node), while x.lastChild

S
accesses the last child of x (the element node B).
So supposing the P is the first child of the body, which in turn is the first child of the document,
you can reach the element node B by either of these commands:
document.firstChild.firstChild.lastChild;
document.firstChild.childNodes[0].lastChild;
document.firstChild.childNodes[0].childNodes[1]; etc.
document.firstChild.childNodes[0].parentNode.firstChild.childNodes[1];
58

DOM Levels and history


A short history lesson in order. When JavaScript was first introduced in browsers, some sort of
interface was required to allow elements on the page to be accessed via scripting. Each vendor
had their own implementation but de facto standards emerged to produce a fairly simple model
common to most.For example, most browsers used an array of Image objects to represent all
IMG tags on a page. These could then be accessed and manipulated via JavaScript. A simple
image rollover might use code like this:
document.images[3].src = "graphics/button2.gif"
These early models were limited. They only provided access to a few types of element and
attributes, like images, links or form elements.As vendors released new versions of browsers,
they expanded on the model. But they also were often at odds with one another, leading to
compatibility problems among different browsers as vendors tried to outdo each other by
m
adding their own new features.Fortunately, most vendors started adopting the DOM standard
o
.c
set by the World Wide Web Consortium, notably Internet Explorer, Netscape and Opera.
In order to provide some backward compatibility, different levels of the DOM standard are

a
defined. You might find references to DOM Level 0 (or "DOM0") which corresponds to the

m
model used by the first, scriptable browsers - mainly Internet Explorer and Netscape prior to

a
version 4 of each. Then there is DOM1 which was adopted in 1998 and covers some of the

n
features introduced in version 4 browsers.Most of the current browsers (version 5 and up)

y
support the DOM2 standard, or at least a good part of it. They may also continue to support

d
some features of the earlier DOM levels, or their own proprietary extensions, so that they are

u
compatible with older web pages.

t
This article will focus just the current, DOM2 standard. While this standard applies to XML

S
(extended markup language) documents in general, it discusses how the standard applies to
HTML in particular (it being a subset of XML).The good news is that, given the current industry
trend, you can expect future versions of browsers to follow this standard. The bad news is that
for now, you may find it difficult to code pages that work with both old and new browsers.
One such example is Netscape 6.0, which drops support for many of the proprietary features of
Netscape 4, such as the LAYER tag and its corresponding Layer object. They are not recognized
in version 6 as they were never adopted as part of the standard.
Also note that Internet Explorer's document.all construct is a proprietary feature, not part of
any standard. While it may be supported in many versions of IE - even the latest version - it's
generally not supported by other browsers. You should keep in mind that the DOM coding is
59

also indirectly dependent on the standards for HTML and CSS, since the DOM reflects the tags
and attributes defined by those standards. It also depends on a standard for JavaScript since the
DOM is essentially and API for client-side scripting.

S.NO RGPV QUESTION YEAR MARKS


Q.1 Explain in detail DOM event June.2014 14
handling. Also explain with an
example of creating a context
menu

m
Q.2 How can you target an element June.2010 4

o
in your HTML using the DOM?

.c
a
m
a
n
y
d
u
t
S
60

UNIT-02/LECTURE-09
Document tree:[RGPV/Jun 2011(10)]
When a browser loads a page, it creates a hierarchical representation of its contents which
closely resembles its HTML structure. This results in a tree-like organization of nodes, each
representing an element, an attribute, content or some other object

Nodes

Each of these different object types will have their own unique methods and properties. But
each also implements the Node interface. This is a common set of methods and properties
related to the document tree structure. To understand this interface better, take a look a the
diagram below which represents a simple node tree.

m
o
.c
a
m
a
The Node object provides several properties to reflect this structure and allow you to traverse
n
the tree. Here are some relationships using the example above:
 NodeA.firstChild = NodeA1
 NodeA.lastChild = NodeA3 y
d
 NodeA.childNodes.length = 3

u
 NodeA.childNodes[0] = NodeA1

t
 NodeA.childNodes[1] = NodeA2
 NodeA.childNodes[2] = NodeA3
S
The Node interface also provides methods for dynamically adding, updating and removing
nodes such as:
 insertBefore()
 replaceChild()
 removeChild()
 appendChild()
 cloneNode()

These will be covered later. But for now let's look how the document tree reflects the contents
of a web page.

The Document Root


61

The document object serves as the root of this node tree. It too implements the Node interface.
It will have child nodes but no parent node or sibling nodes, as it is the starting node. In addition
to being a Node, it also implements the Document interface.

This interface provides methods for accessing and creating other nodes in the document tree.
Some methods are:

 getElementById()

 getElementsByTagName()

 createElement()

 createAttribute()

 createTextNode()

m
Note that unlike other nodes, there is only one document object in a page. All of the above

o
methods (except getElementsByTagName()) can only be used against the document object, i.e.,
using the syntax document.methodName().These properties are intended to provide some

.c
backward compatibility so that pages designed for older browsers will still work properly with
newer versions. They can still be used in scripts but they may not be supported in future
versions.
a
Traversing the Document Tree
m
a
As mentioned, the document tree reflects the structure of a page's HTML code. Every tag or tag

n
pair is represented by a element node with other nodes representing attributes or character
data (i.e., text).
y
d
Technically speaking, the document object has only one child element, given by
document.documentElement. For web pages, this represents the outer HTML tag and it acts as
u
the root element of the document tree. It will have child elements for HEAD and BODY tags

t
which in turn will have other child elements.

S
Using this, and the methods of the Node interface, you can traverse the document tree to
access individual node within the tree. Consider the following:

<html> <head> <title></title> </head>

<body><p>This is a sample paragraph.</p></body> </html>

and this code:

alert(document.documentElement.lastChild.firstChild.tagName);

which would display "P", the name of the tag represented by that node. The code breaks down
as follows:
62

 document.documentElement - gives the page's HTML tag.

 .lastChild - gives the BODY tag.

 .firstChild - gives the first element in the BODY.

 .tagName - gives that element's tag name, "P" in this case.


There are some obvious problems with accessing nodes like this. For one, a simple change to
the page source, like adding text or formatting elements or images, will change the tree
structure. The path used before may no longer point to the intended node.

Less obvious are some browser compatibility issues. Note that in the sample HTML above, there
is no spacing between the BODY tag and the P tag. If some simple line breaks are added,

<html>
<head>
<title></title>
</head>
m
o
<body>

.c
<p>This is a sample paragraph.</p>

</body>
</html> a
m
a
n
Netscape will add a node for this data, while IE will not. So in Netscape, the JavaScript code
shown above would display "undefined" as it now points to the text node for this white space.
y
Since it's not an element node, it has no tag name. IE, on the other hand, does not add nodes

d
for white space like this, so it would still point to the P tag.

u
Accessing Elements Directly

t
S
This is where the document.getElementById() method comes in handy. By adding an ID
attribute to the paragraph tag (or any tag for that matter), you can reference it directly.

<p id="myParagraph">This is a sample paragraph.</p>

...

alert(document.getElementById("myParagraph").tagName);

This way, you can avoid compatibility issues and update the page contents at will without
worrying about where the node for the paragraph tag is in the document tree. Just remember
that each ID needs to be unique to the page.
A less direct method to access element nodes is provided by
document.getElementsByTagName(). This returns an array of nodes representing all of the
elements on a page with the specified HTML tag. For example, you could change color of every
63

link on a page with the following.


var nodeList = document.getElementsByTagName("A");
for (var i = 0; i < nodeList.length; i++) nodeList[i].style.color = "#ff0000";
Which simply updates each link's inline style to set the color parameter to red. Give it a try.

Node Types

Before going further, it's probably a good time to explain node types in more detail. As
mentioned, there are several types of nodes defined in the document object model, but the
ones you'll mostly deal with for web pages are element, text and attribute.
Element nodes, as we've seen, correspond to individual tags or tag pairs in the HTML code. They
can have child nodes, which may be other elements or text nodes.
Text nodes represent content, or character data. They will have a parent node and possibly
sibling nodes, but they cannot have child nodes.
Attribute nodes are a special case. They are not considered a part of the document tree - they
do not have a parent, children or siblings. Instead, they are used to allow access to an element
node's attributes. That is, they represent the attributes defined in an element's HTML tag, such
as the HREF attribute of the A tag or the SRC attribute on the IMG tag.
m
Note that attribute values are always text strings.
o
Attributes vs. Attribute Nodes
.c
a
There are several ways to reference the attributes of an element. The reason for this is that the
DOM2 standard was designed for many types of structured documents (i.e., XML documents),

m
not just HTML. So it defines a formal node type for attributes.

a
But for all documents it also provides some more convenient methods for accessing, adding and

n
modifying attributes, as described next.

y
The document.createAttribute() allows you to create a new attribute node, which you can then

d
set a value for and assign to an element node.

u
var attr = document.createAttribute("myAttribute"); attr.value = "myValue";

t
var el = document.getElementById("myParagraph"); el.setAttributeNode(attr);
S
However, it's usually easier to access an element's attributes directly using the element
getAttribute() and setAttribute() methods instead.

var el = document.getElementById("myParagraph");
el.setAttribute("myAttribute", "myValue");

An element's attributes are also represented as properties of the element node. In other words,
you can simply use
var el = document.getElementById("myParagraph"); el.myAttribute = "myValue";

It's also interesting to note that you can define your own attributes in the HTML tag itself. For
example,
64

...
alert(document.getElementById("myParagraph").getAttribute("myAttribute"));

will display "myAttribute." But note that you should use element.getAttribute(attributeName)
instead of element.attributeName to get the value as some browsers may not register user-
defined attributes as a properties of the element.

Attributes can also be removed from an element node, using either the removeAttribute() or
removeAttributeNode() methods or setting by setting element.attributeName to a null string
("").

Altering attributes is one way to create dynamic effects. Below is a sample paragraph. Use the
links to alter it's ALIGN attribute.

Text in a paragraph element.

Align Left | Align Right


m
The code is fairly simple:
o
<p id="sample1" align="left">Text in a paragraph element.</p>
.c
... code for the links ... a
m
document.getElementById('sample1').setAttribute('align','left');

a
document.getElementById('sample1').setAttribute('align', 'right');

Style Attributes n
y
d
Most attributes for HTML tags are fairly simple, they define a single value for a property specific
to that tag. Styles are a little more involved. As you know, CSS can be used to apply style

u
parameters to an individual tag, all tags of a given type or assigned using

t
classes. Likewise, styles for a particular element can be inherited from any of these sources.

S
You can also alter these styles at various levels. For example, you can change the STYLE attribute
of an HTML tag, or it's CLASS attribute. But these methods will alter all of the element's style
parameters. Often, you may want to change just a single style parameter, or a select few, while
retaining the others.

Fortunately, the style attribute of and element node is defined as an object with properties for
every possible style parameter. You can access and update these individual parameters as you
wish. Here's an example similar to the previous one.

Text in a paragraph element.

Align Left | Align Right

But in this case, the text alignment is defined and altered using a style parameter instead of the
65

<p id="sample2" style="text-align:left;">Text in a paragraph element.</p>

... code for the links ...

document.getElementById('sample2').style.textAlign='left';
document.getElementById('sample2').style.textAlign = 'right';

DOM event handling: [RGPV/Dec 2010(10)]

One of the keys to creating dynamic web pages is the use of event handlers. These allow you to
execute specific script code in response to user or system initiated actions.Most events relate to
the browser GUI, such as mouse movements, button or key clicks and updates to form inputs.
These are usually tied to a specific page element. Others relate to browser actions such as when
m
a document or image completes loading.Some objects have default actions defined for certain
o
.c
events, such as clicking on a hypertext link. The browser's normal action in that event is to load
the URL associated with the link.

a
In any case, all events follow the same model. The DOM provides methods for capturing events

m
so you can perform your own actions in response to them. It also provides an Event object

a
which contains information specific to a given event that can be used by your event processing

n
code.

y
Assigning Event Handlers

d
There are several ways to set up the capture of an event on an object using either HTML or

u
scripting. In each case, you assign a function to handle the specific event when it occurs.

t
S
HTML Tag Attributes
Many HTML tags have intrinsic events associated with them. You can define script code to be
executed when one of these events occurs using the event name as an attribute. For example,

<span style="background-color:yellow;"
onmouseover="this.style.backgroundColor='black';this.style.color='white'"
onmouseout="this.style.backgroundColor='yellow';this.style.color=''"> Sample element with
mouse event handlers.
</span>
66

Here, two different events are captured, mouseover and mouseout. the value assigned to the
corresponding attributes is a string containing JavaScript code. Note the use of single quotes (')
for string constants within the double quotes (") used to delimit the attribute value.The script
code for both events simply changes the text and background colors on the element's style. The
keyword this keyword refers to the object that fired the event. Here it refers to the SPAN
element.It was stated before that when you set up capturing for an event, you assign a function
to be called to handle that event. This seems to contradict the example above where the event
code is simply a couple of JavaScript statements. However, the browser actually creates an
anonymous function for the handler with those statements in it.

You should see an alert box with a function definition. The actual definition will vary according
to browser but it will contain a single statement, the one defined in the HTML:
m
o
.c
function name(argument_list) { alert(this.onclick);
}

a
m
This corresponds to the code set on the ONCLICK attribute:

a
<span style="background-color:yellow;" onclick="alert(this.onclick)">Sample element with an

n
onclick event handler.</span>

y
d
Scripting

u
You can also assign event handlers to elements in the DOM using client-side scripting. Like other

t
element attributes, events are represented as properties of the element object

S
so you can set their value just like any other attribute.The main difference is that unlike most
attributes, which take a string value, event handlers must be set using a function reference.
Here's an example,
<span id="sample1" style="background-color:yellow;">Sample element with mouse event
handlers.</span>
... JavaScript code ...
function highlight(event) {
this.style.backgroundColor='black';
this.style.color='white';
}
67

function normal(event) {
this.style.backgroundColor='yellow';
this.style.color='';
}
document.getElementById('sample1').onmouseover=highlight;
document.getElementById('sample1').onmouseout = normal;
Note that the onmouseover property is set to highlight, i.e., the name of the function without
parenthesis. This represents the Function object for highlight which is what the event property
expects, a reference to the function to call when the event is fired.If highlight() had been used
instead, the browser would call the function and assign whatever value it returned as the event
handler. In this particular case, an error would result in the function execution because this has
no meaning in the given context.
m
o
.c
Event Listeners
DOM objects can also be registered as event listeners. This feature can be used to assign

a
multiple handlers for a given event. It also allows you to capture events during either one of two

m
phases in the event flow, capture or bubble.

a
The difference between these two phases will be covered later on in the discussion on event

n
flow. But for now we'll just look at how to register an event listener.

y
The basic methods and syntax are

d
node.addEventListener(eventType,function,useCapture);

u
node.removeEventListener(eventType, function);

t
where eventType is a predefined event name such as "mouseover" or "click" (the same as the

S
corresponding event attribute but without the preceding "on"), function is the name of the
handler function and useCapture is a boolean flag which specifies which phase of the event flow
the handler will be called on.
To demonstrate, the previous example could have assigned event handlers for the sample
paragraph element with the following:
var el = document.getElementById('sample1'); el.addEventListener("mouseover", highlight,
false); el.addEventListener("mouseout", normal, false);
Additional handlers could also be assigned for a given event:
el.addEventListener("mouseover",highlight2,true);
el.addEventListener("mouseover", highlight3, false);
68

Individual event listeners can be subsequently removed by specifying the same arguments:
el.removeEventListener("mouseover", highlight2, true); el.removeEventListener("mouseover",
highlight3, false);
Note that you must specify the same useCapture value when removing a listener as when it was
added. This is because,
el.addEventListener("mouseover", highlight, true); el.addEventListener("mouseover", highlight,
false);
defines two unique event listeners, calling the same function for the same event on the same
element but which activate during different phases.
One advantage of this method is that event listeners can be assigned to any node, even text
nodes which you could not normally assign event handlers to as they have no attributes.

Event Flow m
o
.c
Before going into event processing, it's helpful to understand event flow in the DOM. HTML
documents (and XML or XHTML documents) are hierarchical in nature. lements and text are

a
nested within other elements. Because of this, when an event occurs on a particular object, it

m
effectively occurs on any containing objects as well.

a
To illustrate, consider the following HTML:

n
<div>

y
<p>Some text in a paragraph element.</p> <p>Another paragraph element with text.</p>

d
<p>Yet another paragraph with text and also a

u
<a href="blank.html">link</a>.</p> </div>

t
If you click on the link defined in this code sample, it will trigger a onclick event on the A tag.

S
But you're also clicking on the paragraph that contains that link, and the DIV that contains that P
element and so on up to the document object itself.Any of the elements in this chain can have
an event handler assigned to it to capture the onclick event, regardless of which element it
originated at.

Event Bubbling

The DOM event model provides for this using a concept called event bubbling. For example,
suppose an onclick event handler were assigned to the DIV tag above. Clicking on the link would
fire the event first on the A element, it would then "bubble" up to the containing P element and
69

then up to the DIV where the handler function would be called.


It's possible for the handler to cancel the event, but assuming it doesn't the event would
continue bubbling on up to the document root and finally, the browser would follow the default
action of loading the link's URL in the window.Note that the P element could also have had an
onclick event handler set, as could any elements above the DIV in the document tree. All of
these handlers would be called in turn as the event bubbles up to the document root.This is
known as the bubble phase in the DOM event model. Not all events bubble, for example
onfocus and onblur do not. Likewise, not all bubbling events can be canceled, stopping the
propagation. You can determine which events bubble and can be canceled either by looking up
the documentation for the event or, as we'll see, using the Event object.

Event Capture
m
You can also catch events during the capture phase using the event listener detailed previously.
o
.c
The capture phase compliments the bubble phase. The capture phase runs first. The event flows
down from the root of the document tree to the target element, then it bubbles back up.

a
In this phase, outer elements will receive the event before it reaches its intended target. This

m
can be useful if you want to intercept an event for some element even if it was initially targeted

a
at one of its children or other descendants.

n
It should be noted that the term "event capture" is often used loosely to describe the act of

y
setting an event handler or listener, during either phase. Here it specifically means intercepting

d
an event during this downward phase of the event flow, before it reaches its intended target.

u
t
Event Flow Example

S
The full process can be illustrated with a demo. Below is a set of nested DIV tags The onclick
event is caught for each element both on the capture phase (if supported by the browser) and
the bubble phase. Click anywhere on the boxes and the path of the event will be traced in the
text box below it.
DIV A
DIV B
DIV C
70

Clicking on the innermost DIV fires six event handlers, three going down the document tree and
three as it bubble back up. In this example, the same function happens to be used for all six. but
each could be assigned a unique handler function.

m
In the trace, the "Target" element is the one that the event initiates from while the "Current"

o
element is the one that has the event listener attached. Both of these values are derived using

.c
the Event object passed to the handler.

The Event Object


a
m
Within an event handler, you can do pretty much anything you want with your script code.

a
Chances are, you'll want to perform some action related to that event depending on one or

n
more factors.Recall that event handlers are passed one argument, an Event object. It provides

y
several properties describing the event and its current state. You can use these to determine

d
where an event originated from and where it currently is in the event flow. Or use the methods

u
it provides to stop the event from flowing on and/or cancel the event.

t
Mouse Events
S
Mouse-related events include:

 click

 mousedown

 mouseup

 mouseover
71

 mouseout

 mousemove

For these events, additional information is provided in the Event object.

Mouse Event Properties

Property Name Description


altKey, ctrlKey, Boolean values. If true, the associated key was depressed when

m
metaKey, shiftKey the event fired.

o
Button An integer indicating which mouse button was pressed or

.c
released, 1 = left, 2 = middle, 3 = right. A one-button mouse will
return only 1, a two-button mouse could return either 1 or 3.
clientX, clientY
a
Give the pixel coordinates of the mouse relative to the client area

m
of the browser, i.e., relative to the viewport, when the event fired.

a
relatedTarget On a mouseover this indicates the node that the mouse has left. On

n
a mouseout it indicates the node the mouse has moved onto.

y
screenX, screenY Give the pixel coordinates of the mouse relative to the screen

d
when the event fired.

u
t
As you can see, these properties can be used to determine the position of the mouse, what

S
buttons are depressed and the elements it is moving over or leaving.

Notes on Mouse Events


Mouse events are always taken to occur on the lowest element in the document tree. That is,
the target of the event will be the most deeply nested element under the mouse when the
event occurs.

Keyboard Events
The DOM2 Event Model does not include specifications for key events. However, the HTML 4
standard does permit the keyup, keydown and keypress events for many elements. Both
72

Netscape 6 and IE 5.5 support these and include properties in the Event object to reflect
information on what key or keys were pressed.In Netscape, the ASCII value of the key is given by
the charCode property on keypress events and in the keyCode property for keydown and keyup
events.Internet Explorer stores the Unicode value of the key in the event keyCode property for
all three key events.

In both, the keydown and keyup events will fire when any modifier key is pressed, such as ALT,
CTRL and SHIFT. The keypress event can be used instead capture combinations such as SHIFT-
A.Some example key combinations with the relevant property values for each key event type
are shown below, arranged by browser.

Handling Events
m
With dozens of different events constantly firing and moving up and down the document tree,
o
.c
the real trick to using event handlers is in figuring out what event to catch, where to attach the
handler and how to process it.

a
Sometimes the answers are obvious and sometimes they aren't. To demonstrate, let's look at a

m
particular effect and see how to implement it using event handlers.

a
Example Using Mouse Events

n
y
Suppose you wanted to create a pop up menu like the one at right. It consists of a DIV tag with

d
several A tags for the individual items. CSS styles are used to achieve the look including a hover

u
effect on the item links.

t
The hover effect could have been done using events but why complicate matters when the CSS

S
:hover pseudo-class does the job? Besides, we'll be using events to handle the hiding and
showing of the menu.
Here's what the CSS and HTML code look like:
.menu { background-color: #40a0c0;
border-color: #80e0ff #006080 #006080 #80e0ff; border-style: solid;
border-width: 2px; position: absolute; left: 0px;
top: 0px; visibility: hidden;
}
a.menuItem { color: #ffffff; cursor: default; display: block;
73

font-family: MS Sans Serif, Arial, Tahoma,sans-serif; font-size: 8pt;


font-weight: bold;
padding: 2px 12px 2px 8px; text-decoration: none;
}
a.menuItem:hover { background-color: #004060;
color: #ffff00;
}
...
<div id="menuId" class="menu">
<a class="menuItem" href="blank.html">Menu Item 1</a> <a class="menuItem"
href="blank.html">Menu Item 2</a> <a class="menuItem" href="blank.html">Menu Item 3</a>
<a class="menuItem" href="blank.html">Menu Item 4</a> <a class="menuItem"
href="blank.html">Menu Item 5</a> </div> m
o
.c
Say we want to make the menu appear at the cursor when the user clicks on a particular link.
We set up a function called openMenu() and add an onclick handler on the A tag like this:
<a href=""
a
m
onclick="openMenu(event, 'menuId'");return false;">Open Menu</a>

a
Notice that openMenu() expects two arguments, an Event object and the ID of the menu DIV to

n
display. Remember that the string value of the ONCLICK attribute is actually used to create an

y
anonymous function which, in this case, would look something like this,

d
function anonymous(event) { openMenu(event, 'menuId'); return false;

u
}

t
with the menu DIV id hard-coded. So the handler really has only one argument, event, as all

S
event handlers do. Returning false will prevent the browser default action of following the link.
Here's the openMenu() function itself:
function openMenu(event, id) {
var el, x, y;
el = document.getElementById(id); if (window.event) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}
else {
x = event.clientX + window.scrollX; y = event.clientY + window.scrollY;
74

}
x -= 2; y -= 2; el.style.left = x + "px"; el.style.top = y + "px";
el.style.visibility = "visible";
}
It basically just positions the menu DIV under the cursor and makes it visible. The positioning is
complicated a bit by the fact that different methods are needed to determine the cursor
position based on the browser.
S.NO RGPV QUESTION YEAR MARKS
Q.1 Explain document object Dec.2010 10
model(DOM) event handling
Q.2 What is document object June.2011 10

m
model? Explain

o
.c
a
REFERENCE m
a
n
BOOK y
AUTHOR PRIORITY
Web d 1
Technologies- u
TCP/IP t
Architecture,S
and Java Achyut S. Godbole and Atul
Programming Kahate
Web 2
Technologies- A
computer
science
perspective Jeffrey C. Jackson
75

m
o
.c
a
m
a
n
y
d
u
t
S
Millions of University Lecture Notes, Book Solutions,
Summary, Assignments and Projects are available for FREE.

Potrebbero piacerti anche