Académique Documents
Professionnel Documents
Culture Documents
WEB FUNDAMENTALS
Sir Tim Berners-Lee is a British computer scientist. He was born in London, and his parents were
early computer scientists, working on one of the earliest computers.
After graduating from Oxford University, Berners-Lee became a software engineer at CERN, the
large particle physics laboratory near Geneva, Switzerland. Scientists come from all over the world
to use its accelerators, but Sir Tim noticed that they were having difficulty sharing information.
In those days, there was different information on different computers, but you had to log on to
different computers to get at it. Also, sometimes you had to learn a different program on each
computer.
Tim thought he saw a way to solve this problem – one that he could see could also have much
broader applications. Already, millions of computers were being connected together through the
fast-developing internet and Berners-Lee realized they could share information by exploiting an
emerging technology called hypertext.
In March 1989, Tim laid out his vision for what would become the web in a document called
“Information Management: A Proposal”.
By October of 1990, Tim had written the three fundamental technologies that remain the foundation
of today’s web (and which you may have seen appear on parts of your web browser):
HTML: HyperText Markup Language. The markup (formatting) language for the web.
URI: Uniform Resource Identifier. A kind of “address” that is unique and used to identify to each
resource on the web. It is also commonly called a URL.
HTTP: Hypertext Transfer Protocol. Allows for the retrieval of linked resources from across the web.
Tim also wrote the first web page editor/browser (“WorldWideWeb.app”) and the first web server
(“httpd“). By the end of 1990, the first web page was served on the open internet, and in 1991,
people outside of CERN were invited to join this new web community.
As the web began to grow, Tim realized that its true potential would only be unleashed if anyone,
anywhere could use it without paying a fee or having to ask for permission.
Tim moved from CERN to the Massachusetts Institute of Technology in 1994 to found the World
Wide Web Consortium (W3C), an international community devoted to developing open web
standards. He remains the Director of W3C to this day.
Decentralisation: No permission is needed from a central authority to post anything on the web,
there is no central controlling node, and so no single point of failure … and no “kill switch”! This also
implies freedom from indiscriminate censorship and surveillance.
Non-discrimination: If I pay to connect to the internet with a certain quality of service, and you pay
to connect with that or a greater quality of service, then we can both communicate at the same level.
This principle of equity is also known as Net Neutrality.
Bottom-up design: Instead of code being written and controlled by a small group of experts, it was
developed in full view of everyone, encouraging maximum participation and experimentation.
Universality: For anyone to be able to publish anything on the web, all the computers involved have
to speak the same languages to each other, no matter what different hardware people are using;
where they live; or what cultural and political beliefs they have. In this way, the web breaks down
silos while still allowing diversity to flourish.
Consensus: For universal standards to work, everyone had to agree to use them. Tim and others
achieved this consensus by giving everyone a say in creating the standards, through a transparent,
participatory process at W3C.
In 2009, Sir Tim established the World Wide Web Foundation. The Web Foundation is advancing
the Open Web as a means to build a just and thriving society by connecting everyone, raising voices
and enhancing participation.
Evolution of the web
1.2 Protocols
A protocol is a set of rules that govern all aspects of communication between two or more partners,
called peers
– These rules are human-made; not like chemistry or physics!
In the networking and communications area, a protocol is the formal specification that defines the
procedures that must be followed when transmitting or receiving data.
Protocols define the format, timing, sequence, and error checking used on the network.
In plain english, the above means that if you have 2 or more devices e.g computers which want to
communicate, then they need a common "Protocol" which is a set of rules that guide the computers
on how and when to talk to each other.
In order to make it reliable, it must be paired with reliable protocol such as TCP at the transport layer.
Internet protocol transmits the data in form of a datagram as shown in the following diagram:
UDP is used by the application that typically transmit small amount of data at one time.
UDP provides protocol port used i.e. UDP message contains both source and destination port
number, that makes it possible for UDP software at the destination to deliver the message to
correct application program.
2 Authentication Yes No
Telnet
Telnet is a protocol used to log in to remote computer on the internet. There are a number of Telnet
clients having user friendly user interface. The following diagram shows a person is logged in to
computer A, and from there, he remote logged into computer B.
Being page oriented every action the application allowed was typically embedded in its own web
page script.
Each script was like a separate transaction which executed the application logic, and generated
the GUI to be sent back to the browser after the application logic was executed.
The GUI was pretty dumb. The browser showed a page.
When the user clicked something in the page, the browser was typically redirected to a new page
(script).
First generation web page technologies include Servlets (Java), JSP (JavaServer Pages), ASP, PHP
and CGI scripts in Perl etc.
GUI logic and application logic was interleaved, making it hard to locate either one when we
needed to make changes to either the GUI or application logic.
Code reuse was low, because the code was spread over a large amount of web page scripts
GUI state (like pressed down buttons) which had to be maintained across multiple pages, had to
be kept either in the session data on the server, or be sent along to each page and back to the
browser again.
If we wanted to change the programming language of the web page scripts (like from PHP to Java
Server Pages (JSP)), that would often require a complete rewrite of the web application. It was a
nightmare.
Frameworks were developed to help make second generation web applications easier to
develop. Examples of such frameworks are ASP.NET (.NET), Struts + Struts 2 (Java), Spring MVC
(Java), JSF (JavaServer Faces), Wicket (Java) Tapestry (Java) and many others.
In the Java community two types of framework designs emerged.
Second generation web applications were easier to develop than first generation web applications,
but they still had some problems.
Despite the better separation of GUI and application logic, the two domains still often got
intertwined in each other. Also, since the GUI logic was written in the same language as the
application logic, changing the programming language meant rewriting the whole application
again.
Additionally, due to the limits of second generation web application technologies, the GUIs
developed were often more primitive than what people were used to from desktop applications.
RIA Web Applications
RIA (Rich Internet Applications) web applications are the third generation of web applications.
RIA web applications were first and foremost known for having a user interface that looked
much closer to desktop applications.
To achieve these more advanced user interfaces, RIA technologies are typically executed in the
browser using either JavaScript, Flash, JavaFX or Silverlight.
As we can see, the GUI logic is now moved from the web server to the browser.
This complete split from the server logic has some positive and negative consequences for the
design and architecture of the application.
First of all, the GUIs can become much more advanced with RIA technologies. That by itself is an
advantage.
Second, because the GUI logic is executed in the browser, the CPU time needed to generate the
GUI is lifted off the server, freeing up more CPU cycles for executing application logic.
Third, GUI state can be kept in the browser, thus further cleaning up the server side of RIA web
applications.
Fourth, the GUI logic completely separated from the application logic, it becomes easier to
develop reusable GUI components, which can be reused no matter what server side
programming language is used for the application logic.
Fifth, RIA technologies typically communicate with the web server by exchanging data, not GUI
code (HTML, CSS and JavaScript). The data exchange is typically XML sent via HTTP, or JSON sent
via HTTP. This changes the server side from being "pages" to being "services" that perform some
part of the application logic (create user, login, store task etc.).
Sixth, the GUI and application logic on the server typically communicate via HTTP + JSON, or
HTTP + XML, the GUI is 100% independent of programming language that is used on the server.
The GUI logic's interface to the server is just HTTP calls.
Seventh, GUI logic and application logic are completely separated, and the only interface
between them is HTTP + JSON / XML, the GUI and application logic can also be developed
independently of each other. The application logic developer can implement the services and
test them independently of the GUI.
Eighth, because the back end just consists of services that send and receive data, it is much easier
add a different type of client in the future, if needed. For instance, we might want to add a native
mobile iOS or Android application client, which also interacts with your back end services.
Ninth, the back end now consist of simple services receiving and sending data, our web
application is naturally prepared for the "open application" trend, where web applications can
be accessed both via a GUI and via an API (in case your users need to write a program to interact
with your web application).
Tenth, the GUI and back end services only exchange data, the traffic load is often smaller than if
the back end had to send the data and HTML, CSS and JavaScript.
RIA Technologies
Here is a list of a few well-known RIA technologies:
HTML5 + CSS3 + JavaScript + JavaScript frameworks
jQuery
jQuery Mobile
AngularJS
Sencha EXT-JS
SmartClient
D3
Dart
GWT (Google Web Toolkit)
JavaFX
Flex (Flash)
Silverlight
Web server is a computer where the web content is stored. Basically web server is used to host the
web sites but there exists other web servers also such as gaming, storage, FTP, email etc.
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 ). A website, also written as web site, or simply site, is a set of related web pages typically
served from a single web domain.Web server" can refer to hardware or software, or both of them
working together.
1. On the hardware side, a web server is a computer that stores a website's component files (e.g. HTML
documents, images, CSS stylesheets, and JavaScript files) and delivers them to the end-user's device. It
is connected to the Internet and can be accessed through a domain name like mozilla.org.
2. On the software side, a web server includes several parts that control how web users access hosted
files, at minimum an HTTP server. An HTTP server is a piece of software that understands URLs (web
addresses) and HTTP (the protocol our browser uses to view webpages).
A static web server, or stack, consists of a computer (hardware) with an HTTP server (software). We
call it "static" because the server sends its hosted files "as-is" to our browser.
A dynamic web server consists of a static web server plus extra software, most commonly an
application server and a database. We call it "dynamic" because the application server updates the
hosted files before sending them to your browser via the HTTP server.
When client sends request for a web page, the web server search for the requested page if
requested page is found then it will send it to client with an HTTP response.
If the requested web page is not found, web server will the send an HTTP response:Error 404
Not found.
If client has requested for some other resources then the web server will contact to the
application server and data store to construct the HTTP response.
Architecture
Web Server Architecture follows the following two approaches:
1. Concurrent Approach
2. Single-Process-Event-Driven Approach.
Concurrent Approach
Concurrent approach allows the web server to handle multiple client requests at the same time. It
can be achieved by following methods:
Multi-process
Multi-threaded
Hybrid method.
Multi-processing
In this a single process (parent process) initiates several single-threaded child processes and
distribute incoming requests to these child processes. Each of the child processes are responsible
for handling single request.
It is the responsibility of parent process to monitor the load and decide if processes should be killed
or forked.
Multi-threaded
Unlike Multi-process, it creates multiple single-threaded process.
Hybrid
It is combination of above two approaches. In this approach multiple process are created and each
process initiates multiple threads. Each of the threads handles one connection. Using multiple
threads in single process results in less load on system resources.
Examples
Apache HTTP Server
Internet Information Services (IIS)
Lighttpd
Sun Java System Web Server
Jigsaw Server
Web browser can show text, audio, video, animation and more. It is the responsibility of a web browser
to interpret text and commands contained in the web page.
Earlier the web browsers were text-based while now a days graphical-based or voice-based web
browsers are also available. Following are the most common web browser available today:
A Web browser acts as an interface between the user and Web server
• Software application that resides on a computer and is used to locate and display Web pages.
• Web user access information from web servers, through a client program called browser.
FEATURES
•All major web browsers allow the user to open multiple information resources at the same time,
either in different browser windows or in different tabs of the same window
• A refresh and stop buttons for refreshing and stopping the loading of current documents
• Home button that gets you to your home page
• Major browsers also include pop-up blockers to prevent unwanted windows from "popping
up" without the user's consent
Most browsers support HTTP Secure and offer quick and easy ways to delete the web cache, cookies.
and browsing history. For a comparison of the current security vulnerabilities of browsers, see
comparison of web browsers.
The primary purpose of a web browser is to bring information resources to the user , allowing them to
view the information and then access other information . This process begins when the user inputs a
Uniform Resource Locator (URL), for example http://www.wikipedia.org into the browser. The prefix
of the URL, the Uniform Resource Identifier or URI, determines how the URL will be interpreted.
The most commonly used kind of URI starts with http: and identifies a resource to be retrieved over the
Hypertext Transfer Protocol (HTTP)
Different types of web browser
Google chrome
Internet explore
Safari
Opera
Mozilla Firefox
Many more
Controller/Dispatcher
Interpreter
Client Programs
Controller works as a control unit in CPU. It takes input from the keyboard or mouse, interpret it and
make other services to work on the basis of input it receives.
Interpreter receives the information from the controller and executes the instruction line by line.
Some interpreter is mandatory while some are optional For example, HTML interpreter program is
mandatory and java interpreter is optional.
Client Program describes the specific protocol that will be used to access a particular service.
Following are the clients programs that are commonly used:
HTTP
SMTP
FTP
NNTP
POP
Web Browser Function:
1.5 HTTP
The Web is a massive distributed client/server information system.
Many applications are running concurrently over the Web, such as web browsing/surfing, e-mail, file
transfer, audio & video streaming, and so on. In order for proper communication to take place
between the client and the server, these applications must agree on a specific application-level
protocol such as HTTP, FTP, SMTP, POP, and etc.
HTTP stands for Hypertext Transfer Protocol. It's the network protocol used to deliver virtually all files
and other data (collectively called resources) on the World Wide Web, whether they're HTML files,
image files, query results, or anything else.
A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then
sends responses back to the client. The standard (and default) port for HTTP servers to listen on is 80
HTTP is a stateless protocol. In other words, the current request does not know what has been done in
the previous requests.
HTTP is core request-response protocol for Web
• Four phases:
• URL,
• Text (data)
– Close connection
• These transactions are stateless. The connection is closed after each page and re-established: Server
can’t connect successive requests from the client
Command Description
POST Requests that server accept data from browser and generate
dynamic content
• POST used for processing forms (dynamic pages and input forms)
• HEAD used to check that content exists
Header Definition
100-102 Informational response; client should respond with some other action
(continue, new protocol) 200-207 Request was successful
200 OK
When this request message reaches the server, the server can take either one of these actions:
1. The server interprets the request received, maps the request into a file under the server's
document directory, and returns the file requested to the client.
2. The server interprets the request received, maps the request into a program kept in the server,
executes the program, and returns the output of the program to the client.
3. The request cannot be satisfied, the server returns an error message.
An example of the HTTP response message is as shown:
HTTP/1.1 200 OK
Date: Sun, 18 Oct 2009 08:56:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT
ETag: "10000000565a5-2c-3e94b66c2e680"
Accept-Ranges: bytes
Content-Length: 44
Connection: close
Content-Type: text/html
X-Pad: avoid browser bug
<html><body><h1>It works!</h1></body></html>
The browser receives the response message, interprets the message and displays the contents of the
message on the browser's window according to the media type of the response (as in the Content-Type
response header). Common media type include "text/plain", "text/html", "image/gif", "image/jpeg",
"audio/mpeg", "video/mpeg", "application/msword", and "application/pdf".
In its idling state, an HTTP server does nothing but listening to the IP address(es) and port(s) specified
in the configuration for incoming request. When a request arrives, the server analyzes the message
header, applies rules specified in the configuration, and takes the appropriate action. The webmaster's
main control over the action of web server is via the configuration.
The network program shall first establish a TCP/IP connection with the server. Once the TCP
connection is established, we can issue the raw request.
A simple HTTP client
The following code uses Socket creates a HTTP client. We can create a HTTP client with URLConnection
or HttpURLConnection. This time we are using more low level api to create the HTTP client. From the
code below we can see that we have to send an HTTP request to the web server.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
//from j a v a 2 s . co m
public class Main {
public static void main(String[] args) throws Exception {
InetAddress addr = InetAddress.getByName("www.google.com");
Socket socket = new Socket(addr, 80);
boolean autoflush = true;
PrintWriter out = new PrintWriter(socket.getOutputStream(), autoflush);
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// send an HTTP request to the web server
out.println("GET / HTTP/1.1");
out.println("Host: www.google.com:80");
out.println("Connection: Close");
out.println();
HTTP/1.1 200 OK
Date: Sun, 07 Oct 2018 06:51:22 GMT
Server: Apache
Last-Modified: Fri, 26 Apr 2013 02:18:20 GMT
Accept-Ranges: bytes
Content-Length: 76
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
Try It?
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b> </body>
</html>
What you just made is a skeleton html document. This is the minimum required information for a web
document and all web documents should contain these basic components. The first tag in your html
document is <html>.This tag tells your browser that this is the start of an html document. The last tag
in your document is </html>.This tag tells your browser that this is the end of the html document.
The text between the <head>tag and the </head>tag is header information. Header information is not
displayed in the browser window.
The text between the <title>tags is the title of your document. The <title>tag is used to uniquely identify
each document and is also displayed in the title bar of the browser window.
The text between the <body>tags is the text that will be displayed in your browser.
The text between the <b>and </b>tags will be displayed in a bold font.
HTML Tags
Physical tags on the other hand provide specific instructions on how to display the text they enclose.
Examples of physical tags include:
<b>: Makes the text bold.
<big>: Makes the text usually one size bigger than what is around it. ƒ
<i>: Makes text italic.
Physical tags were invented to add style to HTML pages because style sheets were not around, though
the original intention of HTML was to not have physical tags. Rather than use physical tags to style your
HTML pages, you should use style sheets.
HTML Elements
Remember the HTML example from the previous page:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b> </body>
</html>
The purpose of the <b>tag is to define an HTML element that should be displayed as bold.
<body>
This is my first homepage. <b>This text is bold</b> </body>
This HTML element starts with the start tag <body>,and ends with the end tag </body>. The purpose of
the <body>tag is to define the HTML element that contains the body of the HTML document.
Nested Tags
You may have noticed in the example above, the <body>tag also contains other tags, like the <b>tab.
When you enclose an element in with multiple tags, the last tag opened should be the first tag closed.
For example:
Note: It doesn't matter which tag is first, but they must be closed in the proper order.
Tag Attributes
Tags can have attributes. Attributes can provide additional information about the HTML elements on
your page. The <tag>tells the browser to do something, while the attribute tells the browser how to
do it. For instance, if we add the bgcolor attribute, we can tell the browser that the background color
of your page should be blue, like this: <body bgcolor="blue">.
This tag defines an HTML table: <table>. With an added border attribute, you can tell the browser that
the table should have no borders: <table border="0">. Attributes always come in name/value pairs like
this: name="value". Attributes are always added to the start tag of an HTML element and the value is
surrounded by quotes.
The most important tags in HTML are tags that define headings, paragraphs and line breaks.
Headings
Headings are defined with the <h1>to <h6>tags. <h1>defines the largest heading while <h6>defines
the smallest.
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
<h4>This is a heading</h4>
<h5>This is a heading</h5>
HTML automatically adds an extra blank line before and after a heading. A useful heading attribute is
align.
<h5 align="left">I can align headings </h5>
Paragraphs
Paragraphs are defined with the <p>tag. Think of a paragraph as a block of text. You can use the align
attribute with a paragraph tag as well.
Important: You must indicate paragraphs with <p> elements. A browser ignores any
indentations or blank lines in the source text. Without <p>elements, the document becomes one
large paragraph. HTML automatically adds an extra blank line before and after a paragraph.
Line Breaks
The <br>tag is used when you want to start a new line, but don't want to start a new paragraph. The
<br>tag forces a line break wherever you place it. It is similar to single spacing in a document.
Horizontal Rule
The <hr>element is used for horizontal rules that act as dividers between sections, like this:
The horizontal rule does not have a closing tag. It takes attributes such as align and width. For
instance:
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment can be placed
anywhere in the document and the browser will ignore everything inside the brackets. You can use
comments to write notes to yourself, or write a helpful message to someone looking at your source
code.
Notice you don't see the text between the tags <!--and -->. If you look at the source code, you would
see the comment. To view the source code for this page, in your browser window, select View and
then select Source.
Note: You need an exclamation point after the opening bracket <!--but not before the closing
bracket -->.
HTML automatically adds an extra blank line before and after some elements, like before and after a
paragraph, and before and after a heading. If you want to insert blank lines into your document, use
the <br>tag.
Try It Out!
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Webpage</h1>
<p>Welcome to my first web page. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br> which I am of
course.</p>
</body
>
</html>
Save the page as mypage2.html. Open the file in your Internet browser. To view how the page
should look, visit this web page: http://profdevtrain.austincc.edu/html/mypage2.html
Character tags like <strong>and <em>produce the same physical display as <b>and <i>but are more
uniformly supported across different browsers.
Some Examples:
The following paragraph uses the <blockquote>tag. In the previous sentence, the blockquote tag is
enclosed in the <samp>Sample tag.
We the people of the United States, in order to form a more perfect Union, establish Justice, insure
domestic Tranquility, provide for the common defense, promote the general Welfare, and secure
the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution
for the United States of America.
Although most browsers render blockquoted text by indenting it, that's not specifically what it's
designed to do. It's conceivable that some future browser may render blockquoted text in some other
way. However, for the time being, it is perfectly safe to indent blocks of text with the <blockquote>.
When you hold your mouse pointer over the WWW, text in the title attribute will appear in.
Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of
an HTML tag. If we want the browser to actually display these characters we must insert character
entities in place of the actual characters themselves.
A character entity has three parts: an ampersand (&), an entity name or an entity number, and finally a
semicolon (;). The & means we are beginning a special character, the ; means ending a special character
and the letters in between are sort of an abbreviation for what it's for. To display a less than sign in an
HTML document we must write: < or < The advantage of using a name instead of a number is
that a name is easier to remember. The disadvantage is that not all browsers support the newest entity
names, while the support for entity numbers is very good in almost all browsers.
Non-breaking Space
The most common character entity in HTML is the non-breaking space . Normally HTML will
truncate spaces in your text. If you add 10 spaces in your text, HTML will remove 9 of them. To add
spaces to your text, use the character entity.
HTML Fonts
The <font> tag in HTML is deprecated. The World Wide Web Consortium (W3C) has removed the
<font>tag from its recommendations. In future versions of HTML, style sheets (CSS) will be used to
define the layout and display properties of HTML elements.
HTML Backgrounds
Backgrounds
The <body>tag has two attributes where you can specify backgrounds. The background can be a color
or an image.
Bgcolor
The bgcolor attribute specifies a background-color for an HTML page. The value of this attribute can be
a hexadecimal number, an RGB value, or a color name:
<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">
Background
The background attribute can also specify a background-image for an HTML page. The value of this
attribute is the URL of the image you want to use. If the image is smaller than the browser window,
the image will repeat itself until it fills the entire browser window.
<body background="clouds.gif">
<body background="http://profdevtrain.austincc.edu/html/graphics/clouds.gif">
The URL can be relative (as in the first line above) or absolute (as in the second line above). If
you want to use a background image, you should keep in mind:
Will the background image increase the loading time too much?
Will the background image look good with other images on the page?
Will the background image look good with the text colors on the page? Will
the background image look good when it is repeated on the page? Will the
background image take away the focus from the text?
Note: The bgcolor, background, and the text attributes in the <body> tag are deprecated in the
latest versions of HTML (HTML 4 and XHTML). The World Wide Web Consortium (W3C) has
removed these attributes from its recommendations. Style sheets (CSS) should be used instead
(to define the layout and display properties of HTML elements).
Try It Out!
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body background="http://profdevtrain.austincc.edu/html/graphics/clouds.gif"
bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text editor and
plain old html.</p>
<p>By learning html, I'll be able to create webpages like a <del>beginner</del> pro....<br>
which I am of course.</p>
</body>
</html>
Save your page as mypage3.html and view it in your browser. To view how the page should look,
visit this web page: http://profdevtrain.austincc.edu/html/mypage3.html
Notice we gave our page a background color as well as a background image. If for some reason the
web page is unable to find the picture, it will display our background color.
HTML Colors
Color Values
Colors are defined using a hexadecimal notation for the combination of red, green, and blue color values
(RGB). The lowest value that can be given to one light source is 0 (hex #00). The highest value is 255
(hex #FF). This table shows the result of combining red, green, and blue:
HTML Lists
HTML provides a simple way to show unordered lists (bullet lists) or ordered lists (numbered lists).
Unordered Lists
An unordered list is a list of items marked with bullets (typically small black circles). An unordered list
starts with the <ul>tag. Each list item starts with the <li>tag.
Definition Lists
Definition lists consist of two parts: a term and a description. To mark up a definition list, you need
three HTML elements; a container <dl>, a definition term <dt>, and a definition description <dd>.
<html>
<head>
<title>My First Webpage</title>
</head>
<body bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text editor and
plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br> which I am of
course.</p>
Here's what I've learned: <ul>
<li>How to use HTML tags</li>
<li>How to use HTML colors</li>
<li>How to create Lists</li> </ul>
</body>
</html>
Save your page as mypage4.html and view it in your browser. To see how your page should look visit
this web page: http://profdevtrain.austincc.edu/html/mypage4.html
HTML Links
HTML uses the <a>anchor tag to create a link to another document or web page.
Email Links
To create an email link, you will use mailto: plus your email address. Here is a link to ACC's Help Desk:
To add a subject for the email message, you would add ?subject=after the email address. For
example:
To link directly to the top section, add a # sign and the name of the anchor to the end of a URL, like
this:
HTML Images
The Image Tag and the Src Attribute
The <img>tag is empty, which means that it contains attributes only and it has no closing tag. To
display an image on a page, you need to use the src attribute. Src stands for "source". The value of the
src attribute is the URL of the image you want to display on your page. The syntax of defining an image:
<img src="graphics/chef.gif">
Not only does the source attribute specify what image to use, but where the image is located. The
above image, graphics/chef.gif, means that the browser will look for the image name chef.gif in a
graphics folder in the same folder as the html document itself.
The browser puts the image where the image tag occurs in the document. If you put an image tag
between two paragraphs, the browser shows the first paragraph, then the image, and then the second
paragraph.
The alt attribute tells the reader what he or she is missing on a page if the browser can't load images.
The browser will then display the alternate text instead of the image. It is a good practice to include
the alt attribute for each image on a page, to improve the display and usefulness of your document
for people who have text-only browsers or use screen readers.
Image Dimensions
When you have an image, the browser usually figures out how big the image is all by itself. If you put
in the image dimensions in pixels however, the browser simply reserves a space for the image, then
loads the rest of the page. Once the entire page is loads it can go back and fill in the images. Without
dimensions, when it runs into an image, the browser has to pause loading the page, load the image,
then continue loading the page. The chef image would then be:
Open the file mypage2.html in your text editor and add code highlighted in bold:
<html>
<head>
<title>My First Webpage</title> </head>
<body>
<h1 align="center">My First Web page</h1>
<p>Welcome to my first webpage. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
<p><img src="graphics/chef.gif" width="130" height="101" alt="Smiling Happy Chef"
align="center"></p>
<p align="center">This is my Chef</p>
</body>
</html>
Tables
Tables are defined with the <table>tag. A table is divided into rows (with the <tr>tag), and each row
is divided into data cells (with the <td>tag). The letters td stands for table data, which is the content
of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables,
etc.
<table border="1">
<tr>
<td>Tables can be used to layout information</td>
<td> <img src="http://profdevtrain.austincc.edu/html/graphics/chef.gif"> </td>
</tr>
</table>
Save your page as mytable1.html and view it in your browser. To see how your page should look
visit this web page: http://profdevtrain.austincc.edu/html/mytable1.html
Headings in a Table
Headings in a table are defined with the <th>tag.
Cell padding is the pixel space between the cell contents and the cell border. The default for this
property is also zero. This feature is not used often, but sometimes comes in handy when you have
your borders turned on and you want the contents to be away from the border a bit for easy viewing.
Cellpadding is invisible, even with the border property turned on. Cellpadding can be handled in a
style sheet.
Table Tags
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or more columns in a table
Table Size
Table Width
The width attribute can be used to define the width of your table. It can be defined as a fixed width
or a relative width. A fixed table width is one where the width of the table is specified in pixels. For
example, this code, <table width="550">, will produce a table that is 550 pixels wide. A relative table
width is specified as a percentage of the width of the visitor's viewing window. Hence this code,
<table width="80%">, will produce a table that occupies 80 percent of the screen.
One very common practice with HTML, is to use HTML tables to format the layout of an HTML
page.
A part of this page is formatted with two columns. As you can see on this page, there is a left
column and a right column. This text is displayed in the left column.
An HTML <table> is used to divide a part of this Web page into two columns. The trick is to use a
table without borders, and maybe a little extra cell-padding. No matter how much text you add to
this page, it will stay inside its column borders.
Let's put everything you've learned together to create a simple page. Open your text editor and type
the following text:
<html>
<head>
<title>My First Web Page </title>
</head>
<body>
<table width="90%" cellpadding="5" cellspacing="0" > <tr
bgcolor="#EDDD9E">
<td width="200" valign="top"><img src="graphics/contact.gif" width="100"
height="100"></td>
<td valign="top"><h1 align="right">Janet Doeson</h1> <h3
align="right">Technical Specialist</h3></td>
</tr>
<tr>
<td width="200">
<h3>Menu</h3>
<ul>
<li><a href="home.html">Home</a></li>
<li> <a href="faq.html">FAQ</a></li>
<li> <a href="contact.html">Contact</a></li>
<li> <a href="http://www.austincc.edu">Links</a> </li>
</ul></td>
<td valign="top"><h2 align="center">Welcome!</h2>
<p>Welcome to my first webpage. I created this webpage without the assistance of a webpage
editor. Just my little text editor and a keen understanding of html.</p>
<p>Look around. Notice I'm able to use paragraphs, lists and headings. You may not be able to
tell, but the layout is done with a table. I'm very clever. </p>
<blockquote>
<p>I always wanted to be somebody, but now I realize I should have been more
specific.</p>
<cite>Lily Tomlin </cite> </blockquote> </td> </tr>
</table>
<hr width="90%" align="left">
<address>
Janet Doeson<br> Technical
Specialist<br>
512.555.5555
</address>
<p>Contact me at <a href="mailto:jdoeson@acme.com">jdoeson@acme.com</a> </p>
</body
</html>
1.7 CSS
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in other media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
External stylesheets are stored in CSS files
Using CSS, you can control the color of the text, the style of fonts, the spacing between
paragraphs, how columns are sized and laid out, what background images or colors are
used, layout designs,variations in display for different devices and screen sizes as well as
a variety of other effects.
CSS is easy to learn and understand but it provides powerful control over the presentation
of an HTML document. Most commonly, CSS is combined with the markup languages
HTML or XHTML.
Advantages of CSS
CSS saves time
Pages load faster
Easy maintenance
Superior styles to HTML
Multiple Device Compatibility
Global web standards
CSS Versions
Cascading Style Sheets level 1 (CSS1) came out of W3C as a recommendation in
December 1996. This version describes the CSS language as well as a simple visual
formatting model for all the HTML tags.
CSS2 became a W3C recommendation in May 1998 and builds on CSS1. This version
adds support for media-specific style sheets e.g. printers and aural devices,
downloadable fonts, element positioning and tables.
CSS Syntax
A CSS comprises of style rules that are interpreted by the browser and then applied to the
corresponding elements in your document. A style rule is made of three parts −
Selector − A selector is an HTML tag at which a style will be applied. This could be any
tag like <h1> or <table> etc.
Property − A property is a type of attribute of HTML tag. Put simply, all the HTML
attributes are converted into CSS properties. They could be color, border etc.
Value − Values are assigned to properties. For example, colorproperty can have value
either red or #F1F1F1 etc.
You can put CSS Style Rule Syntax as follows −
Selector { property: value }
Example
p{
color: red;
text-align: center;
}
You can define selectors in various simple ways based on your comfort.
h1 {
color: #36CFFF;
}
*{
color: #000000;
}
This rule renders the content of every element in our document in black.
The Descendant Selectors
Suppose you want to apply a style rule to a particular element only when it lies inside a
particular element. As given in the following example, style rule will apply to <em> element
only when it lies inside <ul> tag.
ul em {
color: #000000;
}
.black {
color: #000000;
}
This rule renders the content in black for every element with class attribute set to black in
our document. You can make it a bit more particular. For example −
h1.black {
color: #000000;
}
This rule renders the content in black for only <h1> elements with class attribute set to black.
You can apply more than one class selectors to given element. Consider the following example
−
The ID Selectors
You can define style rules based on the id attribute of the elements. All the elements having
that id will be formatted according to the defined rule.
#black {
color: #000000;
}
This rule renders the content in black for every element with id attribute set to black in our
document. You can make it a bit more particular. For example −
h1#black {
color: #000000;
}
This rule renders the content in black for only <h1> elements with id attribute set to black.
The true power of id selectors is when they are used as the foundation for descendant
selectors, For example −
#black h2 {
color: #000000;
}
In this example all level 2 headings will be displayed in black color when those headings will
lie with in tags having id attribute set to black.
The Child Selectors
You have seen the descendant selectors. There is one more type of selector, which is very
similar to descendants but have different functionality. Consider the following example −
body > p {
color: #000000;
}
This rule will render all the paragraphs in black if they are direct child of <body> element.
Other paragraphs put inside other elements like <div> or <td> would not have any effect of
this rule.
Grouping Selectors
You can apply a style to many selectors if you like. Just separate the selectors with a comma,
as given in the following example −
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list
is irrelevant. All the elements in the selector will have the corresponding declarations applied
to them.
You can combine the various id selectors together as shown below −
h1 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
Here all the property and value pairs are separated by a semicolon (;). You can keep them in a single
line or multiple lines. For better readability, we keep them in separate lines.
There are four ways to associate styles with your HTML document. Most commonly used methods
are inline CSS and External CSS.
Embedded CSS - The <style> Element
You can put your CSS rules into an HTML document using the <style> element. This tag is placed
inside the <head>...</head> tags. Rules defined using this syntax will be applied to all the elements
available in the document. Here is the generic syntax −
<!DOCTYPE html>
<html>
<head>
<style type = "text/css" media = "all">
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<body>
<h1 style = "color:#36C;">
This is inline CSS
</h1>
</body>
</html>
<head>
<style>
body {
background-
color: linen;
}
h1 {
color: maroon;
margin-
left: 40px;
}
</style>
</head>
<head>
<link type = "text/css" href = "filename.css" />
</head>
<head>
<@import "URL";
</head>
Here URL is the URL of the style sheet file having style rules. You can use another syntax as well −
<head>
<@import url("URL");
</head>
Example
Following is the example showing you how to import a style sheet file into HTML document
−
<head>
@import "mystyle.css";
</head>
The term network programming refers to writing programs that execute across multiple devices
(computers), in which the devices are all connected to each other using a network.
Socket Programming
Sockets provide the communication mechanism between two computers. A client program creates
a socket on its end of the communication and attempts to connect that socket to a server.
When the connection is made, the server creates a socket object on its end of the communication.
The client and the server can now communicate by writing to and reading from the socket.
The java.net.Socket class represents a socket, and the java.net.ServerSocket class provides a
mechanism for the server program to listen for clients and establish connections with them.
The following steps occur when establishing a TCP connection between two computers using
sockets −
The server instantiates a ServerSocket object, denoting which port number communication
is to occur on.
The server invokes the accept() method of the ServerSocket class. This method waits until a
client connects to the server on the given port.
After the server is waiting, a client instantiates a Socket object, specifying the server name
and the port number to connect to.
The Socket class attempts to connect the client to the specified server and the port number.
If communication is established, the client now has a Socket object capable of communicating
with the server.
On the server side, the accept() method returns a reference to a new socket on the server that
is connected to the client's socket.
After the connections are established, communication can occur using I/O streams. Each socket has
both an OutputStream and an InputStream. The client's OutputStream is connected to the server's
InputStream, and the client's InputStream is connected to the server's OutputStream.
TCP is a two-way communication protocol, hence data can be sent across both streams at the same
time.
Class Description
Socket() Creates an unconnected socket, with the system-
default type of SocketImpl.
public Socket(InetAddress address, int port) Creates a stream socket with specified IP address
to the specified port number.
public Socket(InetAddress host, int port, Uses the DatagramSocket.
boolean stream)
public Socket(InetAddress address, int port, Creates a connection with specified remote address
InetAddress localAddr, int local port) and remote port.
public Socket(Proxy, proxy) Creates a connectionless socket specifying the type
of proxy.
protected Socket(SocketImpl impl) Creates a connectionless Socket with a user-
specified SocketImpl.
Class Description
ServerSocket() Creates an unbound server socket.
ServerSocket(int port) Creates a server socket, bound to the specified port.
ServerSocket(int port, int Creates a server socket, bound to the specified port, with
backlog) specified local port.
ServerSocket(int port, int Creates a server socket, bound to specified port, listen backlog,
backlog, inetAddress bindAddrs) and IP address.
// ClientDemo.java
import java.io.InputStream;
import java.io.DataInputStream;
import java.net.Socket;
public class ClientDemo
{
public static void main(String args[])
{
try
{
Socket s = new Socket("localhost", 7777);
InputStream in = s.getInputStream();
DataInputStream dis = new DataInputStream(in);
String msg = dis.readLine();
System.out.println("Server message is: "+ msg);
dis.close();
s.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
// ServerDemo.java
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.net.ServerSocket;
public class ServerDemo
{
public static void main(String args[])
{
try
{
ServerSocket ss = new ServerSocket(7777);
System.out.println("Server is ready.");
Socket s = ss.accept();
System.out.println("COnnection created.");
System.out.println("Sent message to client.");
OutputStream out = s.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeBytes("Welcome");
dos.close();
s.close();
ss.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}