Concept of WWW.: J.B.Institute of Engineering and Technology
Concept of WWW.: J.B.Institute of Engineering and Technology
Concept of WWW.: J.B.Institute of Engineering and Technology
INTRODUCTION
Concept of WWW.
WWW is stands for World Wide Web.
The World Wide Web (WWW) is a global information medium which users can read and write
via computer connected to the internet.
The Web, or World Wide Web, is basically a system of Internet servers that support specially
formatted documents. The documents are formatted in a markup language called HTML
(Hypertext Markup Language) that supports links to other documents, as well as graphics,
audio, and video files.
In short, World Wide Web (WWW) is collection of text pages, digital photographs, music files,
videos, and animations you can access over the Internet.
Web pages are primarily text documents formatted and annotated with Hypertext Markup
Language (HTML). In addition to formatted text, web pages may contain images, video, and
software components that are rendered in the user's web browser as coherent pages of
multimedia content.
The terms Internet and World Wide Web are often used without much distinction. However,
the two are not the same.
The Internet is a global system of interconnected computer networks. In contrast, the World
Wide Web is one of the services transferred over these networks. It is a collection of text
documents and other resources, linked by hyperlinks and URLs, usually accessed by web
browsers, from web servers.
There are several applications called Web browsers that make it easy to access the World
Wide Web; For example: Firefox ,Microsoft's Internet Explorer, Chrome Etc.
Users access the World-Wide Web facilities via a client called a browser, which provides
transparent access to the WWW servers. User can access WWW via two way such us :
History of WWW:
Tim Berners-Lee, in 1980 was investigating how computer could store information with
random links. In 1989, while working at European Particle Physics Laboratory, he proposed to
idea of global hypertext space in which any network-accessible information could be referred
to by single “universal Document Identifier”. After that in 1990, this idea expanded with
further program and knows as World Wide Web.
Internet and WWW
The Internet, linking your computer to other computers around the world, is a way of
transporting content. The Web is software that lets you use that content…or contribute your
own. The Web, running on the mostly invisible Internet, is what you see and click on in your
computer’s browser.
What is The Internet?
The Internet is a massive network of networks, a networking infrastructure. It connects
millions of computers together globally, forming a network in which any computer can
communicate with any other computer as long as they are both connected to the Internet.
Information that travels over the Internet does so via a variety of languages known as
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
protocols. So we can says that Internet is network of computer which connect to together and
any computer communicate with any other computer.
What is The Web (World Wide Web)?
The World Wide Web, or simply Web, is a way of accessing information over the medium of
the Internet. It is an information-sharing model that is built on top of the Internet.
The Web uses the HTTP protocol, only one of the languages spoken over the Internet, to
transmit data. The Web also utilizes browsers, such as Internet Explorer or Firefox, to access
Web documents called Web pages that are linked to each other via hyperlinks. Web
documents also contain graphics, sounds, text and video.
Different between Internet and WWW
The Web is a Portion of The Internet. The Web is just one of the ways that information can be
disseminated over the Internet. The Internet, not the Web, is also used for email, which relies
on SMTP, Usenet news groups, instant messaging and FTP. So the Web is just a portion of the
Internet.
As mentioned, whenever you enter a URL in the address box of the browser, the browser
translates the URL into a request message according to the specified protocol; and sends the
request message to the server.
For example, the browser translated the URL http://www.test101.com/doc/index.html into
the following request message:
Here,Step by step communication between client and server mention into followingfigure.
Web Browser
Web browser is a client, program, software or tool through which we sent HTTP request to
web server. The main purpose of web browser is to locate the content on the World Wide Web
and display in the shape of web page, image, audio or video form.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
We can also call it a client server because it contacts the web server for desired information. If
the requested data is available in the web server data then it will send back the requested
information again via web browser.
Microsoft Internet Explorer, Mozilla Firefox, Safari, Opera and Google Chrome are examples of
web browser and they are more advanced than earlier web browser because they are capable
to understand the HTML, JavaScript, AJAX, etc. Now days, web browser for mobiles are also
available, which are called micro browser.
Web Server
Web server is a computer system, which provides the web pages via HTTP (Hypertext Transfer
Protocol). IP address and a domain name is essential for every web server.
Whenever, you insert a URL or web address into your web browser, this sends request to the
web address where domain name of your URL is already saved. Then this server collects the all
information of your web page and sends to browser, which you see in form of web page on
your browser.
Lot of web server software is available in the market in shape of NCSA, Apache, Microsoft and
Netscape. Storing, processing and delivering web pages to clients are its main function. All the
communication between client (web browser) and server takes place via HTTP.
Here, we can easily understand concept of web browser and web server by following figure.
Sites like Facebook and MySpace allow users to build and customize their own profile sand
communicate with friends.
o Web Application:
Web application is a broad range of new applications make it possible for users to run
programs directly in a Web browser.as Web logs, these allow users to post thoughts and
updates about their life on the Web.
o User Participation:
In traditional web the contents are solely provider by the web site owner or company, but in
web 2.0 the users participate in content sourcing. This is also known as Crowd sourcing.
Examples: Wikipedia & You Tube.
o Long Tail:
The traditional web was like a retail business the product is sold directly to user and the
revenue generated. But in web 2.0 the niche product is not sold directly but offered as a
service on demand basis and income is generated as monthly fee and pay per consumption.
o Rich User Experience :
Traditional web are built with HTML and CSS CGI and had been offered as a static page. On the
other hand Web 2.0 uses AjaxAsynchronous JavaScript + XML) presenting dynamic, rich user
experience to users.
Example: Google Provided Google Maps and Google Suggest.
Web 2.0 technologies provide a level user interaction that was not available before. Websites
have become much more dynamic and interconnected, producing "online communities" and
making it even easier to share information on the Web. Because most Web 2.0 features are
offered as free services, sites like Wikipedia and Facebook have grown at amazingly fast rates.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Display Resolution
Display resolution is another important factor affecting the Web page design, as we do not have any
control on display resolution of the monitors on which user views our pages.
Display or screen resolution is measured in terms of pixels and common resolutions are 800 X 600
and 1024 X 786.
We have three choices for Web page design.
o Design a web page with fixed resolution.
o Make a flexible design using HTML table to fit into different resolution.
o If the page is displayed on a monitor with a higher resolution, the page is displayed on left-
hand side and some part on the right-hand side remains blank. We can use centered design
to display page properly.
o (Not For Exam) Ideally we should use some frameworks for designing like
Bootstrap/Material design.
Locating Information
Webpage is viewed on a computer screen and the screen can be divided into five major areas such
as center, top, right, bottom and left in this particular order.
The first major area of importance in terms of users viewing pattern is the center, then top, right,
bottom and left in this particular order.
Sitemap
Many a times Web sites are too complex as there are a large number of sections and each section
contains many pages.
It becomes difficult for visitors to quickly move from one part to other.
Once the user selects a particular section and pages in that section, user gets confused about where
he/she is and where to go from there.
To make it simple, keep your hierarchy of information to few levels or provide the navigation bar on
each page to jump directly to a particular section.
UNIT-I
HTML
What is HTML?
Stands for Hypertext Markup Language.
Most documents that appear on the World Wide Web were written in HTML.
HTML is a markup language, not a programming language. In fact, the term HTML is an acronym that
stands for Hypertext Markup Language.
We can apply this markup language to your pages to display text, images, sound and movie files, and
almost any other type of electronic information.
We use the language to format documents and link them together, regardless of the type of
computer with which the file was originally created.
HTML Elements
An element consists of three basic parts: an opening tag, the element's content, and finally, a closing
tag.
<p> - opening paragraph tag
Element Content - paragraph words
</p> - closing tag
Every (web) page requires four critical elements: the html, head, title, and body elements.
1. <html> Element...</html>
o <html> begins and ends each and every web page.
o Its purpose is to encapsulate all the HTML code and describe the HTML document to the
web browser.
<html></html>
2. <head> Element
o The <head> element is "next" as they say. As long as it falls somewhere between your <html>
tag and your web page content (<body>).
o The head functions "behind the scenes." Tags placed within the head element are not directly
displayed by web browsers.
o We will be placing the <title> element here.
o Other elements used for scripting (JavaScript) and formatting (CSS) will eventually be introduced
and you will have to place them within your head element.
<html>
<head>
</head>
</html>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
HTML Tags
o A web browser reads an HTML document top to bottom, left to right.
o Each time the browser finds a tag, it is displayed accordingly (paragraphs look like paragraphs,
tables look like tables, etc).
o Tags have 3 major parts: opening tag(s), content(s), and closing tag(s).
o Recall that a completed tag is termed an element.
<html><body>
<h1>This is heading 1</h1><h2>This is heading 2</h2><h3>This is heading 3</h3>
<h4>This is heading 4</h4><h5>This is heading 5</h5><h6>This is heading 6</h6>
</body></html>
3. Line Breaks
o Line breaks are different then most of the tags we have seen so far. A line break ends the line
you are currently on and resumes on the next line.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<p>Darshan<br />
Computer<br /></p>
HTML Lists
o There are 3 different types of lists.
o A <ol> tag starts an ordered list, <ul> for unordered lists, and <dl> for definition lists.
1. <ul> - unordered list; bullets
2. <ol> - ordered list; numbers
3. <dl> - definition list; dictionary
<ol>
<li>Find a Job</li>
<li>Move Out</li>
</ol>
o Start your ordered list on any number besides 1 using the start attribute.
<ol start="4" >
<li>Buy Food</li>
<li>Get a Degree</li>
</ol>
o There are 4 other types of ordered lists. Instead of generic numbers you can replace them with
Roman numerals or letters, both capital and lower-case. Use the type attribute to change the
numbering.
<oltype="a">
<oltype="A">
<oltype="i">
<ol type="I">
</ol>
<ul>
<li>Milk</li>
<li>Chocolate</li>
</ul>
<oltype="square">
<ol type="disc">
<oltype="circle">
</ol>
<dl>
<dt><b>Fromage</b></dt>
<dd>French word for cheese.</dd>
<dt><b>Voiture</b></dt>
<dd>French word for car.</dd>
</dl>
4. HTML Nested Lists
o You can also nest one list within another, so you could make an unordered list inside a
<html>
<ol>
<li> Clear out garage</li>
<ul>
<li> Tomatoes</li>
</ul>
<li> repair fence </li>
</ol>
</html>
numbered one:
<body bgcolor=”red”>
<font color=”red”>
<body bgcolor=”rgb(72,0,0)”>
<font color=”rgb(72,0,0)”>
<body bgcolor=”#ffff00”>
<font color=”#ffff00”>
1. Font Size
o Set the size of your font with size. The range of accepted values is from 1(smallest) to
7(largest).The default size of a font is 3.
2. Font Color
o Set the color of your font with color.
3. Font Face
o Choose a different font face using any font you have installed.
HTML Code:
<html><body>
<basefont size="2" color="green"><p>This paragraph has had its font...</p>
</basefont>
</body></html>
Internal - href="#anchorname"
Local - href="../pics/picturefile.jpg"
Global - href=http://www.xyz.com/
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Link Targets
o The target attribute defines whether to open the page in a separate window, or to open the link
in the current browser window.
HTML Code:
target=" _blank" Opens new page in a new browser
window
Anchors
o To link to sections of your existing page a name must be given to the anchor.
o In the example below, we've created a mini Table of Contents for this page.
o By placing blank anchors just after each heading, and naming them, we can then create
reference links to those sections on this page as shown below.
o First, the headings of this page contain blank, named anchors. They look like this.
o Now create the reference links, placing the # symbol followed by the name of the anchor in the
href of the new link.
HTML – Images
o Use the <img /> tag to place an image on your web page.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<imgsrc="sunset.gif" />
1. Image src
o Above we have defined the src attribute.
o Src stands for source, the source of the image or more appropriately, where the picture file is
located.
o There are two ways to define the source of an image. First you may use a standard URL.
(src=http://www.Xyz.com/pics/htmlT/sunset.gif) As your second choice, you may copy or upload
the file onto your web server and access it locally using standard directory tree methods.
(src="../sunset.gif")
o The location of this picture file is in relation to your location of your .html file.
URL Types:
Local Src Location Description
src="sunset.gif" picture file resides in same directory as .html file
2. Alternative Attribute
o The alt attribute specifies alternate text to be displayed if for some reason the browser cannot
find the image, or if a user has image files disabled.
5. Images as Links
o Images are very useful for links and can be created with the HTML below.
<a href="http://www.xyz.com/"><imgsrc="sunset.gif"></a>
HTML Forms
o A form will take input from the viewer and depending on your needs, you may store that data
into a file, place an order, gather user statistics, register the person to your web forum, or
maybe subscribe them to your weekly newsletter.
Making a Form
o <form> is main tag to build a form.
o It has a few optional attributes too. Below is an example of the form element.
o The action attribute tells the HTML where to send the collected information, while the method
attribute describes the way to send it.
Type of Input
o The main tag for collecting information from the user is <input>.
o The tag itself contains a name attribute, so that we can refer to the input by a name, and the size
of the entry box in characters.
o There are quite few different types of input to choose from:
o <input type=”text”/> this is the default input type and accepts characters and numbers into a
text box. It can also have a value attribute attached to it, which will give it an initial value.
o <input type=”password”/> this is similar to the above text box but anything that is typed cannot
be seen; instead an asterisk is printed to cover up the entry. As the name suggests, this is used
for password entry.
o <input type=”checkbox”/> this gives a box that can be toggled between checked and unchecked.
It can initially be set to one or the other with checked=”checked”.
o <input type=”radio”/> this is similar to checkbox but in group of radio buttons only one can be
selected at a time. This can also have an initial checked state on one of the radio buttons.
o <input type=”file”/>This will give a box to allow you to choose a file similar to when you open or
save files usually on your machine. It can be used to select a file on the local machine for upload
to a server.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
o <input type=”submit”/> this allows a form to be submitted. When pressed, the information will
be passed on for processing, usually to a script mentioned in the action attribute option of the
form.
o <input type=”image”/> this will also submit the form when selected and, like the img tag,
requires the src attribute to specify an associated image.
o <input type=”button”/> this makes a button available.
o <input type=”reset”/> this will reset the form to its initial state when selected.
o <input type=”hidden”/> this allows hidden data(not seen by the user) to be passed along with
the form.
HTML Tables
o The <table> tag is used to begin a table. Within a table element are the <tr> (table rows) and
<td> (table columns) tags.
<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>
o And now we will change the cellpadding of the table and remove the cellspacing from the
previous example.
1. Name:
Thename attribute specifies thenameofaformwhichisusedtoreferenceelementsinaJavaScript.
2. Action:
The required action attribute specifies where to send the form‐data when a form
issubmitted.
<form action="URL"> Value : URL
Description : Where to send the form data.
3. Method :
The method attribute specifies how to send form‐data (the form‐data is sent to the
pagespecified in the action attribute).
<form method="get|post">
Value : get
Description : Default. Appends the form‐data to the URL in name/value pairs:
URL?name=value&name=value
Value : post
Description : Sends the form‐data as an HTTP post transaction.
4. Target
The target attribute specifies a name or a keyword that indicates where to display the
response that is received after submitting the form.
<form target="_blank|_self|_parent|_top|framename">
Value Description
_blank Theresponseisdisplayedinanewwindowortab
_self Theresponseisdisplayedinthesameframe(thisisdefault)
_parent Theresponseisdisplayedintheparentframe
_top Theresponseisdisplayedinthefullbodyofthewindow
framename Theresponseisdisplayedinanamedframe
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
(2) <span>:
The <span> tag is used to group inline‐elements in a document.
The <span> tag provides no visual change by itself.
The <span> tag provides a way to add a hook to a part of a text or a part of a document.
When the text is hooked in a <span> element you can add styles to the content, or manipulate
thecontent with for example JavaScript.
<p>Mymotherhas<spanstyle="color:lightblue">lightblue</span>eyes.</p>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Introduction to HTML5
The DOCTYPE declaration for HTML5 is very simple:
<!DOCTYPE html>
The character encoding (charset) declaration is also very simple:
<meta charset="UTF-8">
New HTML5 Elements:
o New semantic elements like <header>, <footer>, <article>, and <section>.
o New form control attributes like number, date, time, calendar, and range.
o New graphic elements: <svg> and <canvas>.
o New multimedia elements: <audio> and <video>.
o Elements Removed in HTML5
The following HTML4 elements have been removed from HTML5:
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
<center> CSS
<dir> <ul>
<font> CSS
<frame>
<frameset>
<noframes>
<strike> CSS
<tt> CSS
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
What is CSS?
CSS stands for Cascading Style Sheets
Styles define how to display HTML elements
External Style Sheets can save a lot of work
External Style Sheets are stored in CSS files
Importance of CSS
CSS defines HOW HTML elements are to be displayed.
Styles are normally saved in external .css files. External style sheets enable you to change the
appearance and layout of all the pages in a Web site, just by editing one single file.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
The id Selector
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
The style rule below will be applied to the element with id="para1":
#para1
{ text-align:center; color:red; }
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
.center {text-align:center;}
We can use more than one class in a single element
Explain different ways to write the CSS. / Explain CSS with all types. / Enlist
and explain methods of using CSS in web page.
There are three ways of inserting a style sheet:
o External style sheet
o Internal/Embedded style sheet
o Inline style
1. External Style Sheet
o When using CSS it is preferable to keep the CSS separate from your HTML.
o Placing CSS in a separate file allows the web designer to completely differentiate between
content (HTML) and design (CSS).
o External CSS is a file that contains only CSS code and is saved with a ".css" file extension.
o This CSS file is then referenced in your HTML using the <link> instead of <style>.
File Creation
o Open up notepad.exe, or any other plain text editor and type the following CSS code.
body{ background-color: gray;} p { color: blue; }h3{ color: white; }
o Save the file as a CSS (.css) file.
o Name the file "test.css" (without the quotes). Now create a new HTML file and fill it with
the following code.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<h3> A White Header </h3>
<p> This paragraph has a blue font.
The background color of this page is gray because we changed it with CSS! </p>
</body></html>
o It's much easier to reuse your CSS code if you have it in a separate file. Instead of typing
the same CSS code on every web page you have, simply have many pages refer to a single
CSS file with the "link" tag.
o You can make drastic changes to your web pages with just a few changes in a single CSS
file.
2. Internal/Embedded CSS
o This type of CSS is only for Single Page.
o When using internal CSS, we must add a new tag, <style>, inside the <head> tag. The
HTML code below contains an example of <style>'s usage.
<html><head>
<style type="text/css"></style>
</head><body>
<p>Your page's content!</p></body>
</html>
3. Inline CSS
o It is possible to place CSS right in your HTML code, and this method of CSS usage is
referred to as inline css.
o Inline CSS has the highest priority out of external, internal, and inline CSS.
o This means that you can override styles that are defined in external or internal by using
inline CSS.
o If you want to add a style inside an HTML element all you have to do is specify the desired
CSS properties with the style HTML attribute.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<p style="background: blue; color: white;">A new background andfont color with
inline CSS</p></body>
</html>
body {background-image:url('paper.gif');}
3. Background Image Repeat
o You can have a background image repeat vertically (y-axis), horizontally (x-axis), in both
directions, or in neither direction.
p {background-image: url(smallPic.jpg); background-repeat: repeat; }
h4 {background-image: url(smallPic.jpg); background-repeat: repeat-y; }
ol {background-image: url(smallPic.jpg); background-repeat: repeat-x; }
ul {background-image: url(smallPic.jpg);background-repeat: no-repeat; }
p { font-variant: small-caps; }}
2. Text Indent
o The text-indentation property is used to specify the indentation of the first line of a text.
p { text-indent: 20px; } h5 { text-indent: 30%; }
3. Text Align
o The text-align property is used to set the horizontal alignment of a text.
p { text-align: right; }
h5{ text-align: justify; }
4. Text Transform
o The text-transform property is used to specify uppercase and lowercase letters in a text.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
The top, right, bottom, and left margin can be changed independently using separate properties. A
shorthand margin property can also be used, to change all margins at once.
Value Descriptions
auto The browser calculates a margin
length Specifies a margin in px, pt, cm, etc. Default value is 0px
% Specifies a margin in percent of the width of the
containing element
inherit Specifies that the margin should be inherited from the
parent element
2. Border Width
o The border-width property is used to set the width of the border.
3. Border Color
o The border-color property is used to set the color of the border.
o Border colors can be any color defined by RGB, hexadecimal, or key terms. Below is an
example of each of these types.
4. Border: border-(direction)
o If you would like to place a border on only one side of an HTML element, or maybe have a
unique look for each side of the border, then use border-(direction).
o The direction choices are of course: top, right, bottom, and left. CSS allows you to treat
each side of a border separately from the other three sides.
o Each side can have its own color, width, and style set, as shown below.
p { border-bottom-style: dashed ; border-bottom-color: yellow; border-bottom-width: 5px; }
h4 { border-top-style: double; border-top-color: purple; border-top-width: thick; }
ol { list-style-type: upper-roman; }
ul { list-style-type: circle; }
ul { list-style-image: url("listArrow.gif"); }
ol { list-style-image: url("listArrow2.gif"); }
ul { list-style-position: inside; }
ol { list-style-position: outside; }
Note: "Outside" is actually the default setting for indentation.
a:link {background-color:#B2FF99;}
a:visited {background-color:#FFFF85;}
a:hover {background-color:#FF704D;}
a:active {background-color:#FF704D;}
2. Position Absolute
o With absolute positioning, you define the exact pixel value where the specified HTML
element will appear.
o The point of origin is the top-left of the browser's viewable area, so be sure you are
measuring from that point.
h3 {position: absolute; top: 50px;left: 45px;}
p{position: absolute; top: 75px;left: 75px;}
<body>
<img src="sunset.gif" class="floatLeft"><p>The images are contained with...</p>
<img src="sunset.gif" class="floatRight"><p>This second paragraph has an...</p>
</body>
Introduction to CSS3
CSS3 is the latest standard for CSS.
CSS3 is completely backwards-compatible with earlier versions of CSS.
CSS3 has been split into "modules". It contains the "old CSS specification" (which has been split
into smaller pieces). In addition, new modules are added.
CSS3 Transitions are a presentational effect which allow property changes in CSS values, such as
those that may be defined to occur on :hover or :focus, to occur smoothly over a specified
duration – rather than happening instantaneously as is the normal behaviour.
Transition effects can be applied to a wide variety of CSS properties, including background-color,
width, height, opacity, and many more.
Some of the most important CSS3 modules are:
o Selectors
o Box Model
o Backgrounds and Borders
o Image Values and Replaced Content
o Text Effects
o 2D/3D Transformations
o Animations
o Multiple Column Layout
o User Interface
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
What is JavaScript?
HTML and CSS concentrate on a static rendering of a page; things do not change on the page over
time, or because of events.
To do these things, we use scripting languages, which allow content to change dynamically.
Not only this, but it is possible to interact with the user beyond what is possible with HTML.
Scripts are programs just like any other programming language; they can execute on the client side
or the server.
This is different from client-side scripting where scripts are run by the viewing web browser, usually
in JavaScript.
The primary advantage to server-side scripting is the ability to highly customize the response based
on the user's requirements, access rights, or queries into data stores.
Embedded JavaScript
JavaScript can be embedded in an HTML document.
To embed it in HTML you must write:
<script type=”text/javascript”>
</script>
The script tag has effect of the stopping the JavaScript being printed out as well as indentifying the
code enclosed.
The JavaScript can be placed in the head section of your HTML or the body.
<html>
<body>
<script type=”text/javascript”>
document.write("<h1>This is a heading</h1>");
</script>
</body>
</html>
The Scripts placed in the body section are executed as the page loads and can be used to generate
the content of the page.
As well as the body section, JavaScript can also be placed in the head part.
The advantages of putting a script in there are that it loads before the main body.
External JavaScript
If you want to use the same script on several pages it could be a good idea to place the code in a
separate file, rather than writing it on each.
That way if you want to update the code, or change it, you only need to do it once.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Simply take the code you want in a separate file out of your program and save it with the extension
.js.
<html>
<body>
<script src="myScript.js"></script>
</body>
</html>
JavaScript Variables
Variables in JavaScript behave the same as variables in most popular programming languages (C,
C++, etc) do, but in JavaScript you don't have to declare variables before you use them.
A variable's purpose is to store information so that it can be used later. A variable is a symbolic name
that represents some data that you set.
When using a variable for the first time it is not necessary to use "var" before the variable name.
Variable names must begin with a letter.
Variable names are case sensitive (y and Y are different variables).
var x=5;
var y=6;
var z=x+y;
You can declare many variables in one statement. Just start the statement with var and separate the
variables by comma:
var name="Doe", age=30, job="carpenter";
var name="Doe",
age=30,
job="carpenter";
JavaScript Operators
Operators in JavaScript are very similar to operators that appear in other programming languages.
The definition of an operator is a symbol that is used to perform an operation.
Most often these operations are arithmetic (addition, subtraction, etc), but not always.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Operator Name
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
= Assignment
<body>
<script type="text/JavaScript">
<!--
var two = 2
var ten = 10
varlinebreak = "<br />"
document.write("two plus ten = ")
var result = two + ten
document.write(result)
//-->
</script>
</body>
Assignment Equivalent to
X+=Y X=X+Y
X-=Y X=X-Y
X*=Y X=X*Y
X/=Y X=X/Y
X%=Y X=X%Y
JavaScript Array
An array is a special variable, which can hold more than one value at a time.
The Array object is used to store multiple values in a single variable.
An array can be created in three ways.
The following code creates an Array object called myCars.
1. Regular
varmyCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
2. Condensed
varmyCars=new Array("Saab","Volvo","BMW");
3. Literal
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
varmyCars=["Saab","Volvo","BMW"];
Access an Array
You refer to an element in an array by referring to the index number.
This statement access the value of the first element in myCars.
var name=myCars[0];
JavaScript Functions
A function is a section of code that is separate from the main program.
It is defined once but can be invoked many times.
A function can be passed as parameters so that they can be used and a value can be returned back.
There are some functions already built in to JavaScript, such as the Math.cos() function, which
calculates the cosine of an angle.
An example function could be:
functionmultByTen(x)
{
return x*10;
}
This can then be invoked by using the function’s name complete with any parameters you want to
pass:
mysum=multByTen(3)
<html><body>
<script type=”text/javascript”>
var z= multXbyY(10,15);
document.write(“The result is” +z);
functionmultXbyY(x,y) {
document.write(“x is ” +x);
document.write(“y is ”+y);
return x*y;
}
</script>
</body></html>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
JavaScript Conditions
Conditional statements are used to perform different actions based on different conditions.
In JavaScript we have the following conditional statements:
o if statement - use this statement to execute some code only if a specified condition is true
o if...else statement - use this statement to execute some code if the condition is true and
another code if the condition is false
o if...else if ... else statement - use this statement to select one of many blocks of code to be
executed
o switch statement - use this statement to select one of many blocks of code to be executed
If Statement
Use the if statement to execute some code only if a specified condition is true.
if (condition)
{
code to be executed if condition is true
}
If...else Statement
Use the if....else statement to execute some code if a condition is true and another code if the
condition is not true.
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
if (condition1) {
code to be executed if condition1 is true
}
else if (condition2) {
code to be executed if condition2 is true
}
else {
code to be executed if neither condition1 nor condition2 is true
}
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Switch Statement
Use the switch statement to select one of many blocks of code to be executed.
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some
condition.
variablename=(condition)?value1:value2
voteable=(age<18)?"Too young":"Old enough";
do
{
code block to be executed
}
while (condition);
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
JavaScript Objects
JavaScript has several built-in objects, like String, Date, Array, and more.
An object is just a special kind of data, with properties and methods.
objectName.propertyName
This example uses the length property of the String object to find the length of a string:
var message="Hello World!";
var x=message.length;
person=new Object();
person.firstname="Narendra";
person.lastname="Modi";
person.age=24;
person.eyecolor="blue";
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
function person(firstname, lastname, age)
{
this.firstname = firstname;
this.lastname = lastname;
this. age = age;
}
var person1=new person("Narendra","Modi",24);
document.write(person1.firstname + “ ”+ person1.lastname +” “+ person1.age);
</script>
</body>
</html>
In above the function personbecomes the constructor invoked through the new keyword on
assignment to the person1 variable.
Here the values are passed as parameters to the constructor.
Inside the constructor the this keyword takes on the value of the newly created object and therefore
applies properties to it.
<form name=”userDetails”>
<input type=”text” name= “ fname“/>
<input type=”text” name= “lname“/>
<input type=”submit” name= “ Submit“/>
The form data can then be accessed with various DOM syntax constructions. The form itself can be
accessed through:
document.forms[0];
<script type="text/javascript">
functionincrementCurrent() {
current = parseInt(document.forms["noteForm"].total.value);
document.forms["noteForm"].total.value = current + 1;
}
</script>
</head><body>
<div id="mainDiv">
<h1>Document Object Example</h1>
<form id="noteForm">
Current number of notes:
<input type="text" name="total" value="0" size="3"/>
<input type="button" value="Add a new note"
onclick="incrementCurrent()"/>
</form>
</div>
</body></html>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
The idea behind JavaScript form validation is to provide a method to check the user
enteredinformation before they can even submit it.
JavaScript also lets you display helpful alerts to inform the user what information they have entered
incorrectly and how they can fix it.
<html>
<head>
<title>JavaScript Forms</title>
</head>
<body>
<form method=”post” name=”getinfo” onSubmit=”return processForm()”>
<input type=”text” name=”email”/>
<input type=”submit” value=”log in” name=”Login”/>
</form>
The way it determines this end result is built on the template/pattern in the string emailpattern.
This is used to work out the order of expected characters, how many times they repeat and specially
occurring punctuation.
The string in this case that is used as template is:
“^*\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w+$”
The first section is:
^[\\w-_\.]
This sequence, beginning with ^, means check the first character is a word character represented by
\\w.
The next part is :
*[\\w-_\.]
The * means that the next series of characters described can be represented many times or not at
all.
The characters themselves are the same as before; that is word characters, underscore, hyphen or
period.
\@[\\w]\.+
[\\w]+[\\w]$
The first set in square brackets makes sure that there are some characters after the dot and the last
part checks that the last character is a word character.
In this program after the string is declared, a regular expression object is created with the pattern:
var regex = new RegExp(emailpattern);
The pattern can then be tested against the incoming parameter with object’s test method:
returnregex.test(chkMail);
This will return true or false depending on whether there is a match or not.
• JS Array
• JS Boolean
• JS Math
• JS RegExp
var x=Math.PI;
var y=Math.sqrt(16);
UNIT-II
XML
What is XML?
XML is a meta-language, which can be used to store data & act as a mechanism to transfer
information between dissimilar systems.
XML stands for EXtensible Markup Language.
XML is a markup language much like HTML.
XML was designed to describe data.
XML tags are not predefined in XML. You must define your own tags.
XML is self describing.
XML uses a DTD (Document Type Definition) to formally describe the data.
<?xml version=”1.0”?>
<Person>
<Firstname>Ralph</Firstname>
<Lastname>Mosely</Lastname>
</Person>
Use of XML
Used to exchange data between dissimilar systems.
Used to describe content of document.
XML can be used as database to store data.
Features of XML
XML has its own tag so it’s self describing.
Language Independent:Any language is able to read & write XML.
OS Independent: can be work on any platform.
Readability: It’s a plain text file in user readable format so you can edit or viewin simple editor.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Hierarchical: It has hierarchical structure which is powerful to express complex data and simple to
understand.
<bookstore>
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<file type="gif">computer.gif</file>
Xmlns=”http://www.mydomian.com/ns/animals/1.1”
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Ravi</to>
<from>Ketan</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Ravi</to>
<from>Narendra</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
o This is a copy of the file "note.dtd" containing the Document Type Definition:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<?xml version="1.0"?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
DTD - Elements
In the DTD, XML elements are declared with an element declaration. An element declaration has the
following syntax:
Empty elements
o Empty elements are declared with the keyword EMPTY inside the parentheses:
o #CDATA means the element contains character data that is not supposed to be parsed bya
parser.
o #PCDATA means that the element contains data that IS going to be parsed by a parser.
o The keyword ANY declares an element with any content.
o If a #PCDATA section contains elements, these elements must also be declared.
Elements with children (sequences)
o Elements with one or more children are defined with the name of the children
elementsinside the parentheses:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
o When children are declared in a sequence separated by commas, the children must appearin
the same sequence in the document. In a full declaration, the children must also bedeclared,
and the children can also have children. The full declaration of the notedocument will be:
Wrapping
o If the DTD is to be included in your XML source file, it should be wrapped in aDOCTYPE
definition with the following syntax:
o The example declaration above declares that the child element message can only occurone
time inside the note element.
Declaring minimum one occurrence of the same element
o The * sign in the example above declares that the child element message can occur zeroor
more times inside the note element.
Declaring zero or one occurrences of the same element
o The? Sign in the example above declares that the child element message can occur zeroor
one times inside the note element.
DTD – Attributes
Attributes provide extra information about elements.
Attributes are placed inside the start tag of an element.
Declaring Attributes
o In the DTD, XML element attributes are declared with an ATTLIST declaration. Anattribute
declaration has the following syntax:
o As you can see from the syntax above, the ATTLIST declaration defines the elementwhich
can have the attribute, the name of the attribute, the type of the attribute, and thedefault
attribute value.
o The attribute-type can have the following values:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Value Explanation
CDATA The value is character data
(eval|eval|..) The value must be an enumerated value
ID The value is an unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid XML name
NMTOKENS The value is a list of valid XML names
ENTITY The value is an entity
ENTITIES The value is a list of entities
NOTATION The value is a name of a notation
xml: The value is predefined
DTD example:
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">
XML example:
<square width="100"></square>
o In the above example the element square is defined to be an empty element with
theattributes width of type CDATA. The width attribute has a default value of 0.
XML Schema
An XML Schema describes the structure of an XML document.
XML Schema is an XML-based alternative to DTD.
The XML Schema language is also referred to as XML Schema Definition (XSD).
XML Schema is a W3C Recommendation.
XSD Elements
XML Schemas define the elements of your XML files. It’s of two types:
o Simple
o Complex Type
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
<product pid="1345"/>
o A complex XML element, "employee", which contains only other elements:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
<description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
XSD Attributes
Simple elements cannot have attributes. If an element has attributes, it is considered to be of a
complex type. But the attribute itself is always declared as a simple type.
How to Define an Attribute?
o The syntax for defining an attribute is:
XSL
What is XSL?
XSL stands for EXtensible Stylesheet Language.
XSL = Style Sheets for XML
XSL describes how the XML document should be displayed!
XSL ‐ More Than a Style Sheet Language
XSL consists of three parts:
o XSLT‐a language for transforming XML documents
o XPath‐a language for navigating in XML documents
o XSL‐FO‐a language for formatting XML documents
What is XSLT?
XSLT stands for XSL Transformations.
XSLT is the most important part of XSL.
XSLT transforms an XML document into another XML document.
XSLT uses XPath to navigate in XML documents.
Linking
The style sheet is linked into the XML by adding the connecting statement to the XML document:
<?xml‐stylesheet type=”text/xsl” href=”libstyle.xsl” ?>
XSL Transformations
XSLT is the most important part of XSL.
XSLT is used to transform an XML document into another XML document, or another type of
document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by
transforming each XML element into an (X)HTML element.
With XSLT you can add/remove elements and attributes to or from the output file. You can also
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
rearrange and sort elements, perform tests and make decisions about which elements to hide and
display, and a lot more.
A common way to describe the transformation process is to say that XSLT transforms an XML
source‐tree in to an XML result‐tree.
XSLT Uses XPath:
o XSLT uses XPath to find information in an XML document.
o XPath is used to navigate through elements and attributes in XML documents.
XSLT Works as:
o In the transformation process, XSLT uses XPath to define parts of the source document
that should match one or more predefined templates.
o When a match Is found, XSLT will transform the matching part of the source document
into the result document.
XSL Elements
XSL contains many elements that can be used to manipulate, iterate and select XML, for output.
o value‐of
o for‐each
o sort
o if
o choose
<xsl:value•of> Element
The <xsl:value‐of> element extracts the value of a selected node.
The <xsl:value‐of> element can be used to select the value of an XML element and add it to the
output.
Syntax
<xsl:value‐of select="expression" />
o expression: This is Required. An XPath expression that specifies which node/attribute to
extract the value from. It works like navigating a file system where a forward slash (/) selects
subdirectories.
<xsl:for•each> Element
The XSL <xsl:for‐each> element can be used to select every XML element of a specified node‐set.
<xsl:if> Element
To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL
document.
Syntax
<xsl:if test="expression">
...some output if the expression is
true...
</xsl:if>
<xsl:sort> Element
The <xsl:sort> element is used to sort the output.
<xsl:sort select="artist"/>
The select attribute indicates what XML element to sort on.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<xsl:choose> Element
The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express
multiple conditional tests.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Syntax
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates> Element
The <xsl:apply-templates> element applies a template to the current element or to the current
element's child nodes.
If we add a select attribute to the <xsl:apply-templates> element it will process only the child
element that matches the value of the attribute. We can use the select attribute to specify the order
in which the child nodes are processed.
Look at the following XSL style sheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
</xsl:stylesheet>
sheet available!
The answer to this process the document and style sheet outside of the browser’s own mechanism
for doing this task.
This task can be done either on the client side or the server side.
Using JavaScript
One way to process and transform XML on the client side is using JavaScript, which has several
features for doing the task very well.
<html>
<body>
<script type=”text/javascript”>
//Load the XML document
var xml= new ActiveXObject(“Microsoft.XMLDOM”)
xml.async=false
xml.load(“lib.xml”)
//Load the XSL document
var xsl= new ActiveXObject(“Microsoft.XMLDOM”)
xsl.async= false
xsl.load(“libstyle.xsl”)
//Do the actual transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
Above example shows one way to transform with JavaScript using Microsoft’s proprietary
Application Programming Interface (API) for the Internet Explorer browser.
It is also possible to process XML using the DOM.
Using both the of these mechanisms it is possible to also traverse an XML document and process
either according to a style sheet or simply using the JavaScript to make the stylistic decisions.
Apart from JavaScript, it is also possible to use other programming languages (such as Java and .Net)
to process and then output a transformed document.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
UNIT-V
Open Source
In general, open source refers to any program whose source code is made available for use or
modification.
Open source software is usually developed as a public collaboration and made freely available. It
means can be used without purchasing any license.
Open Source is a certification mark owned by the Open Source Initiative (OSI). Developers of
software that is intended to be freely shared and possibly improved and redistributed by others can
use the Open Source trademark if their distribution terms conform to the OSI's Open Source
Definition. To summarize, the Definition model of distribution terms require that:
The software being distributed must be redistributed to anyone else without any restriction.
The source code must be made available (so that the receiving party will be able to improve
or modify it).
Example of Open Source: Linux, Apache, MySQL, PHP.
PHP
PHP is a general‐purpose server‐side scripting language originally designed for web development to
produce dynamic websites.
PHP scripts execute on web server and serve WebPages to user on request.
PHP was originally created by RasmusLerdorf in 1994. Programmer RasmusLerdorf initially created a
set of C scripts he called "Personal Home Page Tools" to maintain his personal homepage. The scripts
performed tasks such as displaying his résumé and recording his web‐page traffic.
These were released and extended to include a package called the Form Interpreter (PHP/FI). While
PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext
Preprocessor", a recursive acronym.
PHP code is embedded into the HTML source document and interpreted by a web server with a PHP
processor module, which generates the web page document. It also has evolved to include a
command‐line interface capability and can be used in standalone graphical applications.PHP can be
deployed on most web servers and as a standalone interpreter, on almost every operating system
and platform free of charge.
In 1997 ZeevSuraski and AndiGutmans along with Rasmus rewrite PHP and released PHP version 3.0
in June 1998.After this release PHP becomes so much popular.
The PHP version 4.0 was launched in May 2000.This version includes session handling, output
buffering, a richer cire language and support for wide variety of web server platforms.
The PHP 5.0 version released in 2004 with object oriented programming concept.
Web Server
A Web Server is computer and the program installed on it. Web Server interacts with the client
through the browser. It delivers the web pages to the client and to an application by using the web
browser and HTTP protocol respectively.
We can also define the web server as the package of larger number of programs installed on a
computer connected to internet or intranet for downloading the requested files using File Transfer
Protocol, serving e‐ mail and building and publishing web pages.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
A web server works on client server model. A computer connected to internet or intranet must have
a server program.
A computer connected to the internet for providing the services to a small company or a department
store may contain the HTTP server to access and store WebPages and files, SMTP server to support
mail services, FTP server for files downloading and NNTP server for newsgroup.
The computer containing all the above servers is called the web server.
MySQL
MySQL is a relational database management system (RDBMS) that runs as a server providing
multi‐user access to a number of databases.
It is named after developer Michael Widenius' daughter, My. The SQL phrase stands for Structured
Query Language.
The data in MySQL is stored in database objects called tables. A table is a collection of related data
entries and it consists of columns and rows.
The MySQL development project has made its source code available under the terms of the License.
The license can require improved versions of the software to carry a different name or version from
the original software.
First released in January,1998, MySQL was owned and sponsored by the Swedish company MySQL
AB, now owned by Oracle Corporation.
MySQL is fully multithreaded using kernel threads, and provides application programming interfaces
(APIs) for many programming languages, including C,C++, Java, Perl, PHP, Python.
MySQL is used in a wide range of applications, including data warehousing, e‐commerce, Web
databases, logging applications and distributed applications.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
PHP
PHP is a server side scripting that was designed for creating dynamic websites. It slots into your
Apache web server and processes instructions contained in a web page before that page is sent
through to your web browser.
PHP is a powerful scripting language that can be run in the command line of any computer with
PHPinstalled. However, PHP alone isn't enough in order to build dynamic web sites.
Apache
To use PHP on a web site, you need a server that can process PHP scripts. Apache is a free web
Server that, once installed on a computer, allows developers to test PHP scripts locally; this makes it
an invaluable piece of your local development environment.
Like all web servers, Apache accepts an HTTP request and serves an HTTP response.
MySQL
Additionally, dynamic websites are dependent on stored information that can be modified quickly
and easily; this is the main difference between a dynamic site and a static HTML site. However, PHP
doesn’t provide a simple, efficient way to store data. This is where a relational database
management system like MySQL comes into play. PHP provides native support for it and the
database is free, open‐source project.
MySQL is a relational database management system (DBMS). Essentially, this means that MySQL
allows users to store information in a table‐based structure, using rows and columns to organize
different pieces of data.
Numeric Array
Associative Array
Multidimensional Array
Numeric Array
In numeric array each element having numeric key associated with it that is starting from 0;
You can use array() function to create array.
The general syntax is given below:
$array_name=array ( value1, value2 …valueN);
For Example:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<?php
$myarray=array(‘A’,’B’,’C’);
print_r($myarray);
?>
Output:
Array( [0]=>A [1]=>B [2]=>C)
You can refer to individual element of an array in PHP script using its key value as shown below:
<?php
$myarray=array(‘A’,’B’,’C’);
echo $myarray[1];
?>
It will display
B
In Numeric Array you can use for, while or do while loop to iterate through each element in array
because in numeric array key values are consecutive.
<?php
$myarray=array(“Apache”, “MySQL”, “PHP”);
for($i=0;$i<3;$i++)
{
echo $myarray*$i+.”<br>”;
}
?>
Output:
Apache
MySQL
PHP
Associative Array
The associative part means that arrays store element values in association with key values rather
than in a strict linear index order.
If you store an element in an array, in association with a key, all you need to retrieve it later from
that array is the key value.
Key may be either numeric or string.
You can use array() function to create associative array.
The general syntax is given below:
$array_name=array(key1=>value1, key1=>value1,….. keyN=>valueN);
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
For Example 1:
<?php
$myarray=array(5=>”Apple”, 10=>”Mango”, 20=>”Grapes”);
print_r($my_array);
?>
Output:
Array([5]=>Apple [10]=>Mango [20]=>Grapes)
Example 2:
<?php
$myarray=array(“Name”=>”James” , “Age”=>25, “Gender”=>”Male” );
print_r($myarray);
?>
Output:
Array([Name]=>James [Age]=>25 [Gender]=>Male)
You can refer to individual element of an array in PHP using its key value.
Example:
<?php
$myarray=array(“Name”=>”James” , “Age”=>25, “Gender”=>”Male” );
echo “Name:”.$myarray*‘Name’+;
?>
Output:
Name:James
In associative array you cannot use for, while r do..while loop to iterate through each element in
array because in Associative array key value are not consecutive.
So you have to use foreach loop.
For Example:
<?php
$myarray=array(“Name”=>”James” , “Age”=>25, “Gender”=>”Male” );
foreach($myarray as $item)
{
echo $item;
}
?>
Output:
James 25 Male
Multidimensional Array
PHP can easily support multidimensional arrays, with arbitrary numbers of key.And just as in one
dimensional arrays, there is no need to declare out intentions in advance. Assignment can be like:
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
$multi_array*0+*1+*2+*3+=”Good Morning”;
The values those are stored in array can themselves be arrays, just as legitimately as they can be string or
numbers.
For example:
The integer key of 0 stores a string, and the key 1 stores an array that ,in turn, has a string in it.
It is simply an array with two values stored in association with keys.Each of them values is an array itself. We
can reference it like this
echo $basket*‘fruit’+*‘black’+;
$kind=”flower”;
$color=”yellow”;
print(“ $basket *$kind+ *$color+”);
How do you create session & cookie in PHP? Give difference between
session and cookie with example. OR
What are cookies? Explain the cookies handling in PHP with proper
example.
PHP Sessions
A PHP session variable is used to store information about, or change settings for a user session.
Session variables hold information about one single user, and are available to all pages in one
application.
<?phpsession_start(); ?>
<html>
<body>
</body>
</html>
The code above will register the user's session with the server, allow you to start saving user
information, and assign a UID for that user's session.
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>
<html>
<body>
<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>
</body>
</html>
Output:Pageviews=1
In the example below, we create a simple page-views counter. The isset() function checks if the
"views" variable has already been set. If "views" has been set, we can increment our counter. If
"views" doesn't exist, we create a "views" variable, and set it to 1:
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
?>
Destroying a Session
If you wish to delete some session data, you can use the unset() or the session_destroy() function.
The unset() function is used to free the specified session variable:
<?php
unset($_SESSION['views']);
?>
You can also completely destroy the session by calling the session_destroy() function:
<?php
session_destroy();
?>
Note:session_destroy() will reset your session and you will lose all your stored session data.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
PHP Cookie
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer.
Each time the same computer requests a page with a browser, it will send the cookie too. With PHP,
you can both create and retrieve cookie values.
In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it.
We also specify that the cookie should expire after one hour:
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
.....
Note: The value of the cookie is automatically URLencoded when sending the cookie, and
automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).
You can also set the expiration time of the cookie in another way. It may be easier than using
seconds.
<?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?>
<html>
.....
In the example above the expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days).
<?php
// Print a cookie
echo $_COOKIE["user"];
In the following example we use the isset() function to find out if a cookie has been set:
<html>
<body>
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>
</body>
</html>
<html>
<body>
<form action="welcome.php" method="post"> Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
How can you connect to database in PHP? Show the simple database
operation using PHP with proper example.
Integration of PHP with MySQL
It is possible to execute various commands of MySQL from PHP.PHP provides various built-in
functions which you allows you to use MySQL commands from PHP page. Thus you can integrate
PHP with MySQL.
Following are the various PHP functions that allows you the facility of integrating PHP with MySQL:
mysql_connect()
Before you can access data in a database, you must create a connection to the database.
This function allows you to establish connection of PHP application with MySQL server.
Syntax: mysql_connect(servername,username,password);
servername Indicates the name of MySQL server with which you want to establish
connection.
It is optional .Default value is localhost:3306
UserName Indicates the name of user using which you can logs on to MySQL Server.
Optional. Default value is the name of the user that owns the server process.
Password Indicates password of the user using which you can logs on to MySQL Server.
It is optional. Default is "".
If connection establish successfully with MySQL Server then this function returns TRUE value
otherwise it returns FALSE.
Example
<?php
$conn=mysql_connect(“localhost”,”root”,””);
if($conn)
{
echo “Connected with MySQL”;
}
else
{
echo “Could not connect to database”;
}
?>
mysql_select_db()
This function allows you to select database from the list of MySQL server databases.
Syntax: mysql_select_db (DatabaseName, ConnectionName);
DatabaseName Indicates the name of the database that you want to select.
ConnectionName Indicates the name of the variable that is used at the time of establish
connection with MySQL server using mysql_connect() function.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”);
if($db)
{
echo “Database Selected Successfully ”;
}
else
{
echo “Error in selecting Database.”;
}
?>
mysql_query()
This function allows you to specify and execute the MySQL command on MySQL Server.
Syntax:
mysql_query(Query, ConnectionName);
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$cmd=mysql_query(“create table Test(ID integer, Name varchar(20))”);
if($cmd)
{
echo “Table created Successfully ”;
}
else
{
echo “Error in executing query.”;
}
?>
mysql_fetch_row()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
The record that is returned by this function is in the form of numeric array. Numeric array contains
index and value associated with that index.
If there is no record in the record set then it returns false value.
Syntax:
mysql_fetch_row(VariableName);
VariableName indicates the record set that is returned from executing the MySQL command using
mysql_query() function.
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$query=”select * from product_master”;
$result=mysql_query($query,$conn);
$ans=mysql_fetch_row($result);
print_r($ans);
mysql_close($con);
?>
mysql_fetch_array()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query.
The record that is returned by this function is in the form of either numeric array, associative array
or both.
If there is no record in record set then it will returns false value.
Syntax:
mysql_fetch_array(VariableName, ResultArrayType)
VariableName:- indicates the record set that is returned from executing the MySQL command
using mysql_query() function.
ResultArrayType:-indicates the type of array to be returned. It can have one of the following
values:
MYSQL_ASSOC This type of array contains name of the field and the value associated with that
field for current record.
MYSQL_NUM This type of array contains index of the field and the value associcated with that
index for current record.
MYSQL_BOTH It is combination of both Associative array and Numeric array. It is the default
type to be returned by this function.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$query=”select * from product_master”;
$result=mysql_query($query, $conn);
$ans=mysql_fetch_array($result,MYSQL_ASSOC);
print_r($ans);
mysql_close($con);
?>
mysql_fetch_assoc()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query in the form of associative array.
Syntax:
mysql_fetch_assoc(VariableName)
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more
rows.
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$query=”select * from product_master”;
$result=mysql_query($query, $conn);
$ans=mysql_fetch_assoc($result);
print_r($ans);
mysql_close($con);
?>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$query=”select * from product_master”;
$result=mysql_query($query, $conn);
while($ans=mysql_fetch_assoc($result))
{
echo $ans*‘field1’+.”<br>”;
echo $ans*‘field2’+.”<br>”;
}
mysql_close($con);
?>
mysql_num_rows()
This function allows you to retrieve number of records available in the record set.
Syntax:
mysql_num_rows(ResultVariable);
ResultVariable is the variable that holds result returned by mysql_query() function.
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“Mydatabse”, $conn);
$query=”select * from product_master”;
$result=mysql_query($query, $conn);
$total_records=mysql_fetch_rows($result);
echo “Total Records:”.$total_records;
mysql_close($con);
?>
mysql_error()
This function allows you to retrieve theerror text from the most recently executed MySQL
function.
If no error encountered while executing the script then it will returns blank string.
If the mysql operation contains more than one error then it will returns error description of the
last statement in which error is encountered.
Syntax:
mysql_error();
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
if($conn)
{
echo “Connected with MySQL”;
}
else
{
echo “Error:”.mysql_error();
}
?>
mysql_close()
This function allows you to close the connection that is established using mysql_connect()
function.
Syntax:mysql_close(ConnectionName);
ConnectionName :- Indicates the name of the variable that is used at the time of establish
connection with MySQL server using mysql_connect() function.
It returns true is connection is closed successfully otherwise it returns false.
Example:
<?php
$conn=mysql_connect(“localhost”,”root”,””);
mysql_close($con);
?>
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
UNIT-III
Servlet technology is used to create a web application (resides at server side and generates a
dynamic web page).
Servlet technology is robust and scalable because of java language. Before Servlet, CGI (Common
Gateway Interface) scripting language was common as a server-side programming language.
However, there were many disadvantages to this technology. We have discussed these
disadvantages below.
There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet, HttpServlet,
ServletRequest, ServletResponse, etc.
What is a Servlet?
Servlet can be described in many ways, depending on the context.
o Servlet is a technology which is used to create a web application.
o Servlet is an API that provides many interfaces and classes including documentation.
o Servlet is an interface that must be implemented for creating any Servlet.
o Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can
respond to any requests.
o Servlet is a web component that is deployed on the server to create a dynamic web page.
Disadvantages of CGI
There are many problems in CGI technology:
1. If the number of clients increases, it takes more time for sending the response.
2. For each request, it starts a process, and the web server is limited to start processes.
3. It uses platform dependent language e.g. C, C++, perl.
Advantages of Servlet
There are many advantages of Servlet over CGI. The web container creates threads for handling the
multiple requests to the Servlet. Threads have many benefits over the Processes such as they share a common
memory area, lightweight, cost of communication between the threads are low. The advantages of Servlet are as
follows:
1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage collection, etc.
4. Secure: because it uses java language.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Servlet Description
Terminology
Website: static vs It is a collection of related web pages that may contain text, images, audio and video.
dynamic
It is the data communication protocol used to establish communication between client and
HTTP
server.
It is the request send by the computer to a web server that contains all sorts of potentially
HTTP Requests
interesting information.
Get vs Post It gives the difference between GET and POST request.
Container It is used in java for dynamically generating the web pages on the server side.
Server: Web vs It is used to manage the network resources and for running the program or software that
Application provides services.
Content Type It is HTTP header that provides the description about what are you sending to the browser.
SERVLET API
Servlet API consists of two important packages that encapsulates all the important classes
and interface, namely :
javax.servlet
javax.servlet.http
Servlet ServletInputStream
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
ServletContext ServletOutputStream
ServletConfig ServletRequestWrapper
ServletRequest ServletResponseWrapper
ServletResponse ServletRequestEvent
ServletContextListener ServletContextEvent
RequestDispatcher ServletRequestAttributeEvent
SingleThreadModel ServletContextAttributeEvent
Filter ServletException
FilterConfig UnavailableException
FilterChain GenericServlet
ServletRequestListener
HttpServlet HttpServletRequest
HttpServletResponse HttpSessionAttributeListener
HttpSession HttpSessionListener
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Cookie HttpSessionEvent
Servlet Interface
Servlet Interface provides five methods. Out of these five methods, three methods
are Servlet life cycle methods and rest two are non life cycle methods.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
GenericServlet Class
GenericServlet is an abstract class that provides implementation of most of the basic
servlet methods. This is a very important class.
Methods of GenericServlet class
public void init(ServletConfig)
public abstract void service(ServletRequest request,ServletResposne response)
public void destroy()
public ServletConfig getServletConfig()
public String getServletInfo()
public ServletContext getServletContext()
public String getInitParameter(String name)
public Enumeration getInitParameterNames()
public String getServletName()
public void log(String msg)
public void log(String msg, Throwable t)
HttpServlet class
HttpServlet is also an abstract class. This class gives implementation of
various service() methods of Servlet interface.
To create a servlet, we should create a class that extends HttpServlet abstract class. The
Servlet class that we will create, must not override service() method. Our servlet class will
override only the doGet() and/or doPost() methods.
The service() method of HttpServlet class listens to the Http methods (GET, POST etc)
from request stream and invokes doGet() or doPost() methods based on Http Method
type.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
2. The container finds the servlet using deployment descriptor and creates two
objects :
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
a. HttpServletRequest
b. HttpServletResponse
3. Then the container creates or allocates a thread for that request and calls the
Servlet's service() method and passes the request, response objects as arguments.
4. The service() method, then decides which servlet method, doGet() or doPost() to
call, based on HTTP Request Method(Get, Post etc) sent by the client. Suppose the
client sent an HTTP GET request, so the service() will call Servlet's doGet() method.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
5. Then the Servlet uses response object to write the response back to the client.
6. After the service() method is completed the thread dies. And the request and
response objects are ready for garbage collection.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
1. Loading Servlet Class : A Servlet class is loaded when first request for the servlet is received by the
Web Container.
2. Servlet instance creation :After the Servlet class is loaded, Web Container creates the instance of
it. Servlet instance is created only once in the life cycle.
3. Call to the init() method : init() method is called by the Web Container on servlet instance to
initialize the servlet.
Signature of init() method :
public void init(ServletConfig config) throws ServletException
4. Call to the service() method : The containers call the service() method each time the request for
servlet is received. The service() method will then call the doGet() or doPost() methos based ont
eh type of the HTTP request, as explained in previous lessons.
Signature of service() method :
public void service(ServletRequest request, ServletResponse response) throws ServletException,
IOException
5. Call to destroy() method: The Web Container call the destroy() method before removing servlet
instance, giving it a chance for cleanup activity.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
To create a Servlet application you need to follow the below mentioned steps. These
steps are common for all the Web server. In our example we are using Apache Tomcat
server. Apache Tomcat is an open source web server for testing servlets and JSP
technology. Download latest version of Tomcat Server and install it on your machine.
After installing Tomcat Server on your machine follow the below mentioned steps :
1. Create directory structure for your application.
2. Create a Servlet
3. Compile the Servlet
4. Create Deployement Descriptor for your application
5. Start the server and deploy the application
All these 5 steps are explained in details below, lets create our first Servlet Application.
2. Creating a Servlet
There are three different ways to create a servlet.
By implementing Servlet interface
By extending GenericServlet class
By extending HttpServlet class
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
3. Compiling a Servlet
To compile a Servlet a JAR file is required. Different servers require different JAR files. In
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
NOTE: After compiling your Servlet class you will have to paste the class file into WEB-
INF/classes/ directory.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Click on New button, and enter JAVA_HOME inside Variable name text field and
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
UNIT-IV
JSP:
JSP technology is used to create dynamic web applications. JSP pages are easier to maintain then
a Servlet. JSP pages are opposite of Servlets as a servlet adds HTML code inside Java code, while JSP adds
Java code inside HTML using JSP tags. Everything a Servlet can do, a JSP page can also do it.
JSP enables us to write HTML pages containing tags, inside which we can include powerful Java
programs. Using JSP, one can easily separate Presentation and Business logic as a web designer can
design and update JSP pages creating the presentation layer and java developer can write server side
complex computational code without concerning the web design. And both the layers can easily interact
over HTTP requests.
Advantage of JSP
LIFE CYCLE:
A JSP page is converted into Servlet in order to service requests. The translation of a JSP page to a Servlet is
called Lifecycle of JSP. JSP Lifecycle is exactly same as the Servlet Lifecycle, with one additional first step, which
is, translation of JSP code to Servlet code. Following are the JSP Lifecycle steps:
Web Container translates JSP code into a servlet class source(.java) file, then compiles that into a java servlet
class. In the third step, the servlet class bytecode is loaded using classloader. The Container then creates an
instance of that servlet class.
The initialized servlet can now service request. For each request the Web Container call
the _jspService() method. When the Container removes the servlet instance from service, it calls
the jspDestroy() method to perform any required clean up.
A jsp page looks similar to an html page, but a jsp page also has java code in it. We can put
any regular java code in a jsp file using a scriplet tag which start with <% and ends
with %>.
Jsp pages are used to develop dynamic responses.
To learn html, go to html interactive course and learn html while practicing it side by side.
Example of creating a jsp page in eclipse
Open eclipse, click on new → dynamic web project
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
To create a new JSP file right click on Web Content directory, New → JSP file
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
Write something in your JSP file. The complete HTML and the JSP code, goes
inside the <body> tag, just like HTML pages.
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
To run your project, right click on Project, select Run As → Run on Server
WEB TECHNOLOGIES [J.B.INSTITUTE OF ENGINEERING AND TECHNOLOGY]
To start the server, Choose existing server name and click on finish
browser.