Web Technologies (Theory & Practical)
Web Technologies (Theory & Practical)
WEB TECHNOLOGIES:
Theory & Practicals
AUTHOR
Dr. Raman Dugyala
Professor, Computer Science Engineering
Chaitanya Bharathi Institute of Technology, Gandipet
Hyderabad, Telangana - 500075
REVIEWED BY
Dr. Rahul Johari
Associate Professor, Guru Gobind Singh Indraprastha University,
University School of Information and Communication Technology,
E-Block, Sector 16c, Dwarka, Delhi - 110078
(ii)
BOOK AUTHOR DETAILS
Dr. Raman Dugyala, Professor, Computer Science Engineering, Chaitanya Bharathi Institute of Technology,
Gandipet, Hyderabad, Telangana - 500075
Email ID: [email protected]
1. Dr. Ramesh Unnikrishnan, Advisor-II, Training and Learning Bureau, All India Council for Technical
Education (AICTE), New Delhi, India
Email ID: [email protected]
Phone Number: 011-29581215
2. Dr. Sunil Luthra, Director, Training and Learning Bureau, All India Council for Technical Education
(AICTE), New Delhi, India
Email ID: [email protected]
Phone Number: 011-29581210
3. Mr. Sanjoy Das, Assistant Director, Training and Learning Bureau, All India Council for Technical
Education (AICTE), New Delhi, India
Email ID: [email protected]
Phone Number: 011-29581339
May, 2023
© All India Council for Technical Education (AICTE)
ISBN : 978-81-961834-8-6
All rights reserved. No part of this work may be reproduced in any form, by mimeograph or any
other means, without permission in writing from the All India Council for Technical Education
(AICTE).
Further information about All India Council for Technical Education (AICTE) courses may be obtained
from the Council Office at Nelson Mandela Marg, Vasant Kunj, New Delhi-110070.
Printed and published by All India Council for Technical Education (AICTE), New Delhi.
Disclaimer: The website links provided by the author in this book are placed for informational, educational
& reference purpose only. The Publisher do not endorse these website links or the views of the speaker /
content of the said weblinks. In case of any dispute, all legal matters to be settled under Delhi Jurisdiction,
only.
(iii)
(iv)
ACKNOWLEDGEMENT
(v)
PREFACE
(vi)
OUTCOME BASED EDUCATION
For the implementation of an outcome based education the first requirement is to develop
an outcome based curriculum and incorporate an outcome based assessment in the
education system. By going through outcome based assessments, evaluators will be able
to evaluate whether the students have achieved the outlined standard, specific and
measurable outcomes. With the proper incorporation of outcome based education there
will be a definite commitment to achieve a minimum standard for all learners without
giving up at any level. At the end of the programme running with the aid of outcome
based education, a student will be able to arrive at the following outcomes:
Programme Outcomes (POs) are statements that describe what students are expected
to know and be able to do upon graduating from the program. These relate to the skills,
knowledge, analytical ability attitude and behaviour that students acquire through the
program. The POs essentially indicate what the students can do from subject-wise
knowledge acquired by them during the program. As such, POs define the professional
profile of an engineering diploma graduate.
National Board of Accreditation (NBA) has defined the following seven POs for an
Engineering diploma graduate:
PO1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics,
science and engineering fundamentals and engineering specialization to solve the
engineering problems.
PO2. Problem analysis: Identify and analyses well-defined engineering problems using
codified standard methods.
PO3. Design/ development of solutions: Design solutions for well-defined technical
problems and assist with the design of systems components or processes to meet
specified needs.
PO4. Engineering Tools, Experimentation and Testing: Apply modern engineering
tools and appropriate technique to conduct standard tests and measurements.
PO5. Engineering practices for society, sustainability and environment: Apply
appropriate technology in context of society, sustainability, environment and ethical
practices.
(vii)
PO6. Project Management: Use engineering management principles individually, as a
team member or a leader to manage projects and effectively communicate about
well-defined engineering activities.
PO7. Life-long learning: Ability to analyse individual needs and engage in updating in
the context of technological changes.
(viii)
COURSE OUTCOMES
CO-1 3 3 3 3 1 1 3
CO-2 3 2 2 2 1 1 3
CO-3 3 2 2 2 1 1 3
CO-4 3 2 2 3 1 1 3
CO-5 3 3 3 3 1 1 3
(ix)
GUIDELINES FOR TEACHERS
To implement Outcome Based Education (OBE) knowledge level and skill set of the
students should be enhanced. Teachers should take a major responsibility for the proper
implementation of OBE. Some of the responsibilities (not limited to) for the teachers in
OBE system may be as follows:
Within reasonable constraint, they should manoeuvre time to the best advantage
of all students.
They should assess the students only upon certain defined criterion without
considering any other potential ineligibility to discriminate them.
They should try to grow the learning abilities of the students to a certain level
before they leave the institute.
They should try to ensure that all the students are equipped with the quality
knowledge as well as competence after they finish their education.
They should always encourage the students to develop their ultimate performance
capabilities.
They should facilitate and encourage group work and team work to consolidate
newer approach.
They should follow Blooms taxonomy in every part of the assessment.
Bloom’s Taxonomy
Teacher should Student should be Possible Mode of
Level
Check able to Assessment
Students ability to
Create Design or Create Mini project
create
Students ability to
Evaluate Argue or Defend Assignment
justify
Students ability to Differentiate or Project/Lab
Analyse
distinguish Distinguish Methodology
Students ability to Operate or Technical Presentation/
Apply
use information Demonstrate Demonstration
Students ability to
Understand Explain or Classify Presentation/Seminar
explain the ideas
Students ability to
Remember Define or Recall Quiz
recall (or remember)
(x)
GUIDELINES FOR STUDENTS
Students should take equal responsibility for implementing the OBE. Some of the
responsibilities (not limited to) for the students in OBE system are as follows:
Students should be well aware of each UO before the start of a unit in each and
every course.
Students should be well aware of each CO before the start of the course.
Students should be well aware of each PO before the start of the programme.
Students should think critically and reasonably with proper reflection and action.
Learning of the students should be connected and integrated with practical and
real life consequences.
Students should be well aware of their competency at every level of OBE.
(xi)
CONTENTS
Foreword iv
Acknowledgement v
Preface vi
Outcome Based Education viii
Course Outcomes ix
Guidelines for Teachers x
Guidelines for Students xi
(xiii)
4.19. XSLT 140
4.20. Introduction to Web Services 148
Unit Summary 152
Exercise 152
References and suggested readings 157
Unit 5 PHP 158-192
5 Introduction to PHP 159
5.1. PHP characteristics 160
5.2. Features of PHP 160
5.3. Advantages of PHP over other scripting languages 161
5.4. Creating a PHP Script 162
5.5. PHP Variables 162
5.6. Exploring Data types in PHP 164
5.7. Operators in PHP 167
5.8. Type Casting 169
5.9. Control Structures 170
5.10. Arrays 171
5.11. User-defined Functions in PHP 172
5.12. Working with forms 175
5.13. Working with Databases 177
5.14. Features of phpMyAdmin 180
Unit Summary 190
Exercise 190
References and suggested readings 192
Refernces and Further Learning 193
CO and PO Attainment Table 194
Index 195
(xiv)
1 | Web Systems Architecture
1 Introduction to WWW
UNIT SPECIFICS
MA
1. PROTOCOL:
A protocol is basically a standard that makes it possible to connect, communicate, and transfer
data between two locations on a network. In other words, the protocols are digital languages that are
implemented as networking algorithms. Users use several networks and network protocols when
surfing.
1.1. Types of protocols:
I. HTTP:
The Hyper Text Transfer Protocol (HTTP) is a standard for information transfer on the
internet that is used to transfer hypertext documents. The formatting and transmission
standards are described in this protocol. It also details the various actions web browsers
are expected to take in response to requests to access a particular web page. Every
moment a person launches a web browser, they are inadvertently using HTTP, which is
the protocol used to share text, images, and other multimedia on the World Wide Web.
II. HTTPS:
Hypertext Transfer Protocol over Secure Socket Layer is known as HTTPS. Consider it
an HTTP version with security. Most websites that request personal or sensitive
information do so via HTTPS (such as a password or your credit card details).
SSL is used when you view a website utilising HTTPS (Secure Sockets Layer). An
SSL certificate must be deployed on the server for a website to use HTTPS. These are
typically issued by a Certificate Authority, which is a reputable third party (CA).
When utilising HTTPS to browse a website, you can view the SSL certificate's
details. You may, for instance, verify its legitimacy. You might also make sure the
website really does belong to the company you believe it does. Typically, you can do
this by twice clicking on the padlock icon on the browser. You only see the padlock
icon when you access a secure website.
III. FTP
Its shorthand name is FTP, or File Transfer Protocol. Online file transfers are done
with it. Updates to a website are routinely uploaded through FTP by web developers
(i.e., to upload a new version of the website).
Web Technologies: Theory & Practicals | 3
In contrast to HTTP, which uses it to display the file in your browser, FTP just uses
the file to send it from one computer to a specific location on another computer. FTP
can be used to transfer files from your computer to a remote computer, such as a web
server, or from the distant computer to your local computer.
IV. TCP/IP
Different computer types can communicate with one another using the Transmission
Control Protocol/Internet Protocol. The IP protocol requires that each computer
connected to the Internet have a special serial number, or IP address. TCP specifies
how data should be converted into IP packets and how it should be transferred across
the internet. It also verifies that the message was transmitted to the intended recipient
correctly and that the packets contain information about the message's source,
destination, and the sequence in which the message contents should be reassembled.
V. SMTP
These protocols, such as the Simple Mail Transfer Protocol, are necessary for sending
and dispersing outbound emails. This protocol adds the message to the list of outgoing
mails after reading the recipient's email address from the message header. Additionally,
it removes the email from the outgoing list after sending it to the recipient's email
address.
VI. TELNET
Terminal Network: The TCP/IP protocol TELNET is used by the ISO's virtual terminal
service. This makes it possible for local machines to connect to one another. The
computer that is connected is referred to as the remote computer, and the computer that
is connecting is referred to as the local computer. We can view any activity taking place
on the remote computer in the local computer using TELNET operation. This uses the
client/server model to operate. The telnet client programme is used by the local
computer, while the telnet server application is used by the remote computer.
VII. POP3
Post Office Protocol 3: POP3 is the abbreviation for Post Office Protocol version 3.
Both of its message access agents (MAAs), the client MAA and the server MAA, are
utilised to access the messages in the mailbox. We can retrieve and manage emails from
the mailbox on the recipient mail server to the recipient's computer with the aid of this
protocol. Between the receiver and recipient mail server, this is implied.
1.2. WEB PROGRAM
Web program is a code for a web page. You need a web browser to run a web page source code.
Just like any program you require different languages to code a webpage. HTML is the most
basic language used to create a webpage.While there are many different programming languages,
the most common ones used in web development are JavaScript, HTML, CSS, PHP etc.,
4 | Introduction to WWW
1.4.2 Advantages:
There are numerous uses for web applications, and these usage offer numerous potential
advantages. Common advantages of Web applications include:
Providing access to the same application version for numerous users.
Web apps don't require installation.
You can see web apps on a range of gadgets, such as a desktop, laptop, or smartphone.
Accessible with a variety of browsers.
1.5. Web Developments tools
Building websites and apps for the internet, or an intranet, is a process known as web
development. Writers of the code that defines things like style, layout, and interactivity are
known as web developers. They work to make a website's design and functionality come to
life. All of the tools we use online, from the most basic static web pages to social media
platforms and applications; e-commerce websites to content management systems (like
WordPress), have been created by web developers..
The frontend, the backend, and database technology are the three different sorts (or
layers) of web development. Frontend development, also referred to as client-side scripting,
includes all of the components of a website that the user sees and interacts with directly.
The frontend is responsible for things like menus, contact forms, and layout.
The focus of backend development, often known as server-side scripting, is on the
background operations. The frontend notifies the backend when you interact with a website
in some way, such filling out a form and clicking "submit." In response, the backend sends
the necessary data to the frontend, such as the code required to display a message like
"Thank you for completing this form."
Technology related to databases makes up the third layer. All files and content
required for a website to run are stored in the database in a manner that makes it simple to
access, organise, update, and save.
A fully functional website or application is created and maintained by combining the
efforts of the frontend, backend, and database technologies. As a result, these three layers
serve as the basis for web development.
Web developers can test and debug their code using web development tools, often
known as devtools or inspect elements. They differ from website builders and integrated
development environments (IDEs) in that they serve as tools for assessing a website's or
web application's user interface rather than being directly involved in the creation of a
webpage.
Web browsers either have built-in functions or add-ons that are used for web
development. Most popular web browsers, such as Google Chrome, Firefox, Internet
Explorer, Safari, Microsoft Edge and Opera, have built-in tools to help web developers, and
many additional add-ons can be found in their respective plugin download centres.
Developers can work with a range of web technologies thanks to web development
tools. including HTML, CSS, the DOM, JavaScript, and other components that are handled
by the web browser. Due to increasing demand from web browsers to do more, popular web
browsers have included more features geared for developers.
6 | Introduction to WWW
• However, it is not an open source project, therefore adding customised modules and
making changes can be challenging.
III. Nginx web server
Nginx is another open-source, free web server. High performance, stability, ease of
configuration, and resource efficiency are some of its best qualities.
Instead of using threads to process requests, this web server employs an event-driven
design that is far more scalable and requires minimal, predictable amounts of
memory while it is under demand.
IV. LightSpeed web server
A high-performance drop-in replacement for Apache is LiteSpeed (LSWS). The most
widely used commercial web server on the internet is called LSWS.
Switching to LiteSpeed for your web server will enhance performance and reduce running
costs
1.8. DYNAMIC IP
When a computing device or network node connects to a network, it is given a temporary IP
address called a dynamic Internet Protocol address (dynamic IP address). Every new network
node is given a dynamic IP address, which is an automatically configured IP address, by a DHCP
server.
Internet service providers and networks with a lot of connecting clients or end-nodes typically use
dynamic IP addresses. Unlike static IP addresses, dynamic IP addresses are not permanent. A
dynamic IP is assigned to a node until it’s connected to the network; therefore, the same node
may have a different IP address every time it reconnects with the network.
A Dynamic Host Configuration Protocol (DHCP) server controls the assignment, reassignment,
and adjustment of dynamic IP addresses. One of the primary reasons behind having dynamic IP
addresses is the shortage of static IP address on IPv4. Dynamic IP addresses allow a single IP
address to be shuffled between many different nodes to circumvent this problem.
1.9. WEB DESIGNING
1.9.1 Principles of good Website design
An excellent website should engage visitors and effectively convey its desired
message. Consistency, colours, font, graphics, simplicity, and usefulness are just a few
factors that contribute to good website design.
Numerous significant design factors affect how a website is perceived. Creating trust
with consumers is one way that a well-designed website can motivate people to take action.
Making sure your website design is optimised for usability (form and aesthetics) and how
easy it is to use is crucial to establishing a positive user experience (functionality).
I. Website purpose
The user's needs must be met by your website. Each page should have a straightforward
goal to let the consumer interact with what you have to offer. What does your website
aim to achieve? Are you delivering useful knowledge, such as a "How to guide"? Is it a
website that offers amusement, such as sports coverage, or are you trying to sell the
8 | Introduction to WWW
user something? Websites may serve a variety of functions, yet they all have certain
fundamental goals;
Defining Expertise
Developing Your Reputation
Creating Leads
Sales and After Care
II. Simplicity
When thinking about how to improve your website's usability and user experience,
simplicity is the best approach. Here are some strategies for designing for simplicity.
Colour: Color has the power to evoke feelings and transmit messages. By
selecting a colour scheme that complements your brand, you may influence how
your customers interact with it. No more than five different colours should be
used. Harmonious colour combinations are quite powerful. Appealing colour
selections raise consumer engagement and enhance user mood.
Type: On your website, typography has a crucial part to play. It grabs the
audience's interest and serves as the visual representation of the brand voice. On
the website, typefaces should be readable, and there should be no more than three
different fonts.
Imagery: An image is any visual device used in communication. This includes
not only still photography, but also film, illustration, and all forms of graphics.
Every image used by the corporation should reflect its brand identity while also
capturing the spirit of the enterprise. It's important to utilise high-quality images
as a first impression to give visitors a sense of professionalism and credibility
because the majority of the initial information we ingest on websites is visual.
III. Navigation
Users interact with the navigation system on websites to find the content they are
looking for. A website needs good navigation to keep users there. If a website's
navigation is challenging, visitors will give up on using it and search elsewhere for
what they need. It's critical to maintain consistent, simple-to-use navigation throughout
each page.
IV. F-shaped pattern reading
The most popular pattern used by website visitors to scan text is the F-based pattern.
According to eye-tracking studies, people tend to focus mostly on the top and left
portions of the screen. The F-shaped layout corresponds to the way we naturally read in
the West (left to right and top to bottom). A website that is well built will accommodate
a reader's natural tendency to scan the page.
V. Visual hierarchy
The grouping of items according to importance is known as visual hierarchy. Size,
colour, images, contrast, font, whitespace, texture, and style are some ways to do this.
Establishing a focus point is one of the most crucial uses of visual hierarchy since it lets
viewers know where the most crucial information is located.
Web Technologies: Theory & Practicals | 9
VI. Content
Both outstanding design and amazing content are found on an efficient website. Great
content may attract and influence visitors by turning them into clients by using
language that is captivating.
VII. Grid based layout
Grids support design organisation and content organisation. The grid makes the page
look neat and aligns the elements on the page. A website's appearance is improved by
the grid-based layout, which organises content into a neat, rigid grid structure with
columns and sections that feel balanced and impose order.
VIII. Load time
A website will lose visitors if you wait for it to load. Nearly half of website visitors
anticipate that a page will load in two seconds or less, and they may leave if it takes
more than three seconds. Optimizing picture sizes will make your website load more
quickly.
IX. Mobile friendly
More people are browsing the web on their phones or other gadgets. It is crucial to
think about creating your website with a responsive layout so that it can adapt to
various devices.
how organised it is, all of that stuff simply doesn't always fit in a single, broad menu.
Although many websites require more than two, all websites have major and secondary
main menus.
The stuff that the majority of people are interested in is designated as primary
navigation. However, value varies; on some websites, the same sort of content may be
linked from the primary navigation and the secondary navigation (for example, general
information about the company or person).
For stuff that only slightly interests the user, there is secondary navigation. This
section would house any content that users could still find interesting but does not
directly advance the website's main objective. This would typically feature links to
"About us," "Contribute," "Advertise," and other pages for many blogs. The client area,
FAQ, or support page for other websites may be accessible via the links.
The organisation of the content comes first in the navigation process. You can only
decide what is primary and what is secondary once the information has been structured,
and only then can you decide where to put any remaining content and how to navigate
through it. In alternative menus, whether a submenu, footer menu, sidebar widget, or
anyplace else, content that does not match the major or secondary navigation can be
placed. Not to imply that primary navigation cannot appear in these locations on the
page; there are numerous situations in which drop-down menus or the sidebar make the
most sense for primary navigation.
Also, consider whether anything other than the main menu requires navigating. If a
supplementary menu is required, why is it so, and how should it be implemented?
Regardless of how well organised the content is, if there is a lot of it and you need a
more complicated navigational structure, it can be difficult to distinguish between
primary and secondary content..
The content may be arranged in accordance with the order of steps the user must
do if it in any way depicts a process (such as "How to pay your taxes").
I. Common considerations
The main focuses of navigation design are usability and findability. No matter how easy
or difficult it is, navigation must be effective for its consumers. We'll now examine
several navigational patterns and how these styles may help or hurt websites.
II. Horizontal vs. Vertical
The purpose and design of the website often determine whether to move horizontally or
vertically. Most of the time, it's a combination of both, but with primary navigation, we
notice some patterns. While major corporate websites frequently employ both
horizontal and vertical navigation, small websites frequently use the horizontal
navigation at the top of the page (usually with drop-down menus). The principal
navigation of blogs can occasionally be horizontal (for pages or categories, for
example), while the majority of the other menus are vertical. The navigation on news
websites is inconsistent, with no obvious trend in either direction.
The decision to use horizontal navigation as opposed to vertical navigation will be
influenced by a number of factors, including design, usability, and content density. To
make the navigation stand out more, designers will occasionally add icons or graphic
components to the area around it. Rich typography is another typical factor: as the
website's navigation is the most visited region, it might receive a specific typographic
treatment to enhance and differentiate the user experience.
It would be impossible to put Amazon's departments list into a horizontal menu
without it looking crowded. Instead, there is a search bar across the top, which
functions as navigation in and of itself. Perhaps significantly more frequently than on
other websites, many Amazon shoppers use the search box first because they know
exactly what they want. The departmental menu for Amazon is located on the left. The
list's primary use is surfing because it is so extensive and diversified, and vertical
menus are useful for browsing. The user can narrow down their department and product
browsing with the help of the vertical sub-menus.
Simple primary menus should normally be horizontal, however this is not required.
Here are a couple layouts that successfully employ vertical menus as the main
navigation. A website with a lot of material may quickly overshadow vertical menus,
yet all of these websites have straightforward menus and relatively simple designs. The
first site down, Good/Corps, is a good illustration of how a lot of information may be
presented in a very condensed, even minimalistic style. Users can clearly see the site's
hierarchy because subsections are indented.Good/Corps
Baltic International Bank
Divensis
Debbie Millman
Analogue Digital
Mellasat
Cambrian House
Stura TU-Chemnitz
12 | Introduction to WWW
Of course, horizontal menus can be very effective as well, and best practices-compliant
menus don't have to be uninteresting. In fact, it's even possible to combine horizontal
and vertical menus.
Below is a brief demonstration of primary or secondary level horizontal menus in use.
Moody International
The Big Feastival
Web Standards Sherpa
Tijuana Flats
Unlocking.com
Cultural Solutions
Tinkering Monkey
JustBurns
Unit Summary
We have understood the Protocols and Web Programs related to Web Browser. We have also got
introduced to Server and It’s Configuration. We have also learnt about Dynamic IP and Web
Designing Principles, Planning the site and Navigation
EXERCISE
Multiple Choice Questions
1.1 Expansion of FTP is __________
a) Fine Transfer Protocol
b) File Transfer Protocol
c) First Transfer Protocol
d) Fast Transfer Protocol
1.4. TCP process may not write and read data at the same speed. So we need __________ for storage.
a) Packets
b) Buffers
c) Segments
d) Stacks
1.5 To achieve reliable transport in TCP, _________ is used to check the safe and sound arrival of
data.
a) Packet
b) Buffer
14 | Introduction to WWW
c) Segment
d) Acknowledgment
1. Teach Yourself Java (PROGRAMMING & WEB DEV - OMG) (16 September, 1998) by
Joseph O'Neil (Author)
2. Introduction to Networking Protocols and Architecture (wustl.edu)
3. https://amzn.eu/d/4R3Idjv
4. O Level Made Simple – Web Designing & Publishing (M2-R5) by Prof. Satish Jain and M.
Geetha Iyer
UNIT SPECIFICS
Through this unit we will discuss the following aspects:
Architecture of Web based systems.
Building blocks of fast and scalable data access Concepts.
Load Balancers-queues.
Web Application Architectures.
RATIONALE
This unit focuses on the Web Application Architecture and the blocks in it such as web
page it’s types, web browser and web server as well. Understanding the underlying
technology, the formats and standards on which the web server is built, as well as the
tiers involved in it and the benefits of tiered architecture, is necessary for developing
web-models and databases and it’s access methods their role in web server
architectures and different web component models and its importance in web system
architecture
PRE-REQUISITES
Problem Solving Skills
Object Oriented Programming
UNIT OUTCOMES
List of outcomes of this unit is as follows:
U2-O1: Describe the basic Architecture of Web Based Systems
U2-O2: Explain the tiered Architectures of Web Servers
U2-O3: Explain the fast and scalable data access concepts.
U2-O4: Explain the Web Application Architecture.
U2-O5: Apply the Web Application Component Models
Web Technologies: Theory & Practicals | 17
2.1. Introduction
You will typically use web browser software like Internet Explorer or Mozilla Firefox when
you browse the Internet. A client system is a machine running a web browser, whereas
a server system is a system that serves up web pages.
Your computer establishes a network connection to a Web Server when you dial up to an
Internet Service Provider (ISP). In this case, your computer functions as a client
connected to an ISP web server. The web server, as its name implies, provides Web
pages to your browser.
“Before understanding the architecture of a web base system let us know about web Browser,
web pages, types of web pages, tiers”.
Python, Ruby, etc. this is also known as the Logical Layer. Between the
Presentation layer and the Database layer, this layer serves as an intermediary.
The whole business logic will be written in this layer. It also goes by the name
middleware.
A Data Layer, a database administration tool that gives users access to
application data. a database that includes data sets and RDBMS software for
managing and accessing the data (back-end). For example, this could be MSSQL,
MySQL, or Oracle. It includes methods for connecting to the database and doing
necessary operations. Delete, update, etc., are a few examples.
v. It makes the code base easier to maintain by maintaining presentation code and
business logic separately so that, for example, a change to business logic won't
affect the presentation layer.
2.1.6. The Various Web Based application architecture available
are:
1. One-tier architecture
2. Client/Server Two-tier architecture
3. Three-tier architecture
Limitation:
Tough to update.
Not scalable. i.e., Tough to increase volume of processing (Scalability)
Moving to a new machine requires rewriting everything. (Portability)
Did not protect valuable "Business Logic”.
Changing of one layer needs to change others. (maintenance)
Limitations
Business-logic is implemented on the Personal Computers
Increased network traffic
prevents the reuse of application logic
necessitates the design and implementation of a protocol for client-server
communication.
DB Server
Client Server
Caches, proxies, indexes, load balancers, and queues are the building
blocks of a scalable data access layer.
2.3. Caches:
Caches are ubiquitous in computing. Their ability to scale read access in a
system is clear. They “take advantage of the locality of reference
principle: recently requested data is likely to be requested again.”
When clients avoid “taxing downstream levels”, they enable more growth
in the system without the need to scale out. For example, assuming
linear scaling and equally taxing requests, if clients implement caching
that reduces their usage of the backend by 50%, then the backend can
handle twice as many clients without purchasing more resources.
2.3.1. Cache placement
Request Node: collocate the cache with the node that requests the data
Advantage
The node can swiftly respond to cached data if it is present whenever
a request is made, preventing any network hops.
Often in-memory and very fast
Limitation
When you have multiple request nodes that are load balanced, you
may have to cache the same item on all the nodes
2.3.2. Global Cache:
Central cache used by all request nodes
Advantage
A given item will only be cached only once
Multiple requests for an item can be collapsed into one request to
the backend
Limitation
Easy to overwhelm a single cache as the number of clients and
requests increase
2.3.3. Types
i. Reverse proxy cache: cache is responsible for retrieval on cache miss (more
common, handles its own eviction)
ii. Cache as a service: request nodes are responsible for retrieval on cache
miss (typically used when the request nodes understand the eviction
strategy or hot spots better than the cache)
Web Technologies: Theory & Practicals | 23
iii. Distributed Cache: each of the nodes that make up the cache own part of
the cached data; divided using a consistent hashing function
Advantage
Cache space and load capacity can be increased by scaling out
(increasing the number of nodes)
Limitation
Node failure must be handled or intentionally ignored
2.4. Proxies
Proxies are a deceptively simple building block in an architecture: their very
nature is to be lightweight, nearly invisible components yet they can
provide incredible value to a system by reducing load on the backend
servers, providing a convenient location for caching layers, and funnelling
traffic appropriately.
2.4.1. Collapsed forwarding
Collapsed forwarding is an example of a technique that proxies can employ
to decrease load on a downstream server. In this technique, similar
requests are collapsed into a single request that is made to the
downstream server; the result of this request is then written to all
similar requests, thus reducing the number of requests made.
A simple example of collapsed forwarding is deduplication. If a resource X is
requested 100 times, the proxy can make a single request to retrieve X
from the downstream server and then write the same response body
to the other 99 requests for X.
This is particularly helpful for the downstream server when resource X is
large in size. Let’s assume a 5 MB payload that must be read into
memory (rather than streamed). Without deduplication, the hundred
requests would require the server to wastefully read 5 * 99 = 495 MB
into memory. The deduplication step in the proxy can smooth over
spikes and reduce the memory usage dramatically.
24 | Web Systems Architecture
2.5. Indexes
When most developers hear the word “indexes”, they immediately jump to
database indexes.
Indexes are helpful in the data access layers above the database. Consider a
system which is backed by multiple database clusters. Creating an index
that maps keys to the database responsible for those keys would
eliminate the need to query multiple databases.
2.5.1. Multiple layers of indexes
Once the correct cluster has been identified, another index layer may
identify the node within the cluster, and so on. This leads to the point
that often-creating multiple layers of indexes is worth the increased
write latency. This figure from the chapter illustrates how multiple
indexes can guide reads to the correct data:
Web Technologies: Theory & Practicals | 25
2.5.2. Views
Indexes also allow the same underlying data to be organized differently
without resorting to copying through the use of views.
Additionally, indexes can be utilised to generate numerous views of the
same data. This is an excellent approach to specify various filters and
sorts for huge data sets without having to make numerous additional
copies of the data.
2.6. Load balancers
Any architecture must include load balancers since they spread load among a
group of nodes in charge of processing requests. This enables various
nodes in a system to transparently service the same function.
Like caches, load balancers are placed in many strategic places throughout an
architecture. They are also implemented in a variety of ways.
2.7. Queues
Unlike proxies and load balancers which augment an existing architecture and
scale reads, queues have a more dramatic impact on the data flow of
the architecture and scale writes. Queues have this impact by forcing
the introduction of asynchronous processing.
While a synchronous system tightly couples a request to its immediate
response, an asynchronous system separates the two. This is achieved
by having clients provide a work request to the queue which is not
26 | Web Systems Architecture
The web application architecture is essential in the present world since the
majority of apps and devices, as well as a significant amount of the
global network traffic, rely on web-based communication.
In addition to dealing with efficiency, a web application architecture must also
address resilience, scalability, stability, and security.
2.8.1. What is the way it works?
Two distinct programmes (codes) run simultaneously in any typical web
application. that are:
i. Code that runs in the browser and reacts to user input is known as
client-side code.
ii. Server-side Code - The server-side programme that replies to HTTP
requests
The web developer (team) creating the web application makes the decisions
for how the server code will interact with the browser code. C#, Java,
JavaScript, Python, PHP, Ruby, and other languages are employed for
building server-side programming.
Any programme that has the capacity to reply to HTTP requests is capable of
running on a server. The user's requested page is created by the
server-side code, which is also in charge of keeping various forms of
data, such as user profiles and user input. The end-user never sees it.
This web application component model needs at least two web servers.
It's everything to prevent failure. One of the web servers can still
function while the other takes over.
All incoming requests will be instantly sent to the new server, where the
web application will continue to run. As a result, the server with
implicit database is less reliable. But if the database fails, the web
application will also fail.
iii. Multiple Web Servers and Databases
Due to the lack of a single point of failure in the webservers or
databases, it is the most effective component model for online
applications. For this kind of model, there are two choices. to
evenly distribute data throughout all active databases, or to
ensure consistency between them.
For the former, normally no more than 2 databases are needed,
however for the latter, in the event of a database crash, some
data may become unavailable. But in both cases, DBMS
normalisation is applied.
When the scale is big Installing load balancers is, such as when there are
more than 5 web servers, databases or both.
2.8.4. The Architecture Types of Web Application:
An interaction pattern between different web application components is
known as a web application architecture. How the application
functionality is split between the client and server sides determines
the type of web application architecture.
The web application architecture majorly contains three main forms. The
following is an explanation of each of them:
i. Single-Page Apps (SPAs)
Single page web applications allow for dynamic interaction by updating
material on the currently shown page rather than downloading
new pages from the server each time a user takes a step.
AJAX, a condensed version of asynchronous JavaScript and XML, is the
building block that makes page communications possible and, in
turn, makes SPAs a possibility. Because they avoid user
interruptions, single-page applications resemble traditional
desktop applications in several aspects.
30 | Web Systems Architecture
Error Logs
Not contain any points of failure.
Provide a consistent and uniform response to the question.
Adherence to the most recent standards and technologies
Increased security measures should be used to reduce the likelihood of
harmful intrusions.
Unit Summary
Through this unit we have understood the Architecture of Web based systems and Building
blocks of fast and scalable data access Concepts. We have also learnt about the Load Balancers-
queue and Web Application Architectures.
EXERCISE
Multiple Choice Questions
1.1 A ________ web page is not interactive and is used to display information only.
a) Dynamic
b) Static
c) Server
d) Client
1.2 A ________ web page is not interactive and is used to display information only.
a) Dynamic
b) Static
c) Server
d) Client
1.3 The background color of a Web page is determined by the ______ property.
a) BackColor
b) BackgroundColor
c) BgColor
d) BColor
1.7 The basic Web Services platform is combination of _____ and _______
a) CSS + HTTP
b) XML + HTML
c) XML + HTTP
d) CSS + JAVA
1. Web Components in Action by Ben Farrell Foreword by Gray Norton August 2019 ISBN
9781617295775 432 pages
2. What is Web Application Architecture? Components, Models, and Types
(hackr.io)https://amzn.eu/d/4R3Idjv
3. Web Application Architecture: Principles, Protocols and Practices 1st Edition by Leon Shklar
(Author), Rich Rosen (Author)
4. Web Application Architecture: Components, Models, and Types (scnsoft.com)
Dynamic QR CODE for further reading
34 | Java Script Introduction
UNIT SPECIFICS
Through this unit we will discuss the following aspects:
Client-side Scripting.
Building blocks of java Scripts.
Functions in Java Script.
Loops and repetition.
RATIONALE
This unit completely focuses on the Introduction to JavaScript. It basically deals with
client-side scripting and its importance in web applications. It also deals with definition of
java script and it’s characteristics, features and the limitations as well. How to embed
java script in HTML java script types such as External script and Internal script, the
various function blocks like variables, keywords, comments, conditional statements and
operators too. The unit also covers arrays and functions.
PRE-REQUISITES
Problem Solving Skills
Object Oriented Programming
UNIT OUTCOMES
List of outcomes of this unit is as follows:
U3-O1: Explain the Client-Side Programming
U3-O2: Explain the introductory concepts of Script
U3-O3: Explain the Constructs of Java Script.
U3-O4: Explain the arrays in Java Script.
U3-O5: Apply the functions in Java Script
Web Technologies: Theory & Practicals | 35
MA
3.2. JavaScript:
A script is a program code written using a Scripting language.
36 | Java Script Introduction
3.2.2. Limitations:
JavaScript does not allow reading or writing of files (For Security Reason).
Not support to develop network applications.
Doesn’t have any multithreading or multiprocessor capabilities.
Web Technologies: Theory & Practicals | 37
==, !=
&&,||, ?:
=,+=, -=, *=,|=,%=
The scope of variables can be local to the block, function and global.
Example:
function add (a, b, c)
{
var avg = (a+b+c)/3;
return avg;
}
The function can be called as var y = add (10, 20, 30);
3.7.1. Built in functions of JavaScript
I. alert () –
Used to display information a pop up box/ message box. (dialog)
Used to display error messages once a form is validated.
Defined in “window “object.
window.alert (“message”); or alert (“message”);
Example: window.alert (“enter a valid phone
no”);
II. prompt () –
displays a message box containing a text box with OK & Cancel
Buttons
It returns a text string when OK is clicked and null when cancel is
42 | Java Script Introduction
clicked. Used to accept input data from the user for script code.
defined in “windows” object.
window.prompt (“message”, “default value”); or window.prompt
(“message”);
Example: var no = window.prompt (“enter a no”,
“o”); var no = prompt (“enter a no”);
III. Confirm () –
display a dialog box with two buttons OK & Cancel. When OK is
clicked, returns true otherwise returns false.
Used to take user confirmation.
defined in “windows” object.
window.confirm (“would you like to do?”); or confirm (“message
here”);
Example: window.confirm(“save or not ?”);
IV. isFinite () –
checks whether a value is finite or not.
Returns true if the argument is a finite value.
Var isFinite (arg)
Example: var x = isFinite (204);
document.writeln (x); //true.
V. isNaN () –
checks whether a value is number or not.
(NaN) --> Not a number.
returns true if the argument is string,
isNaN (arg);
Example: var x = isNaN (“welcome”); //true
var y = isNaN (“2022”); //false
VI. ParseInt () –
It parses the string and returns the first integer value found in
the string.
ParseInt(string);
Web Technologies: Theory & Practicals | 43
Unit Summary
Through this unit we have larnt about the Client-side Scripting and Building blocks of java
Scripts. We have also understood the key concepts viz., Functions in Java Script Loops and
repetition.
44 | Java Script Introduction
EXERCISE
Multiple Choice Questions
1.1 DHTML is a combination of _________ and __________.
a) DOM and CSS
b) CSS and Conventional HTML
c) HTML and JavaScript
d) None of the above
1.2 Which type of JavaScript language is ___
a) Object-Oriented
b) Object-Based
c) Assembly-language
d) High-level
1.3 The "function" and " var" are known as:
a) Keywords
b) Data types
c) Declaration statements
d) Prototypes
1.4. Which one of the following is the correct way for calling the JavaScript code?
a) Pre-processor
b) Triggering Event
c) RMI
d) Function/Method
1.5 Which of the following type of a variable is volatile?
a) Mutable variable
b) Dynamic variable
c) Volatile variable
d) Immutable variable
1.6 In JavaScript the x===y statement implies that:
a) Both x and y are equal in value, type and reference address as well.
b) Both are x and y are equal in value only.
c) Both are equal in the value and data type.
d) Both are not same at all.
Web Technologies: Theory & Practicals | 45
1.7 In JavaScript, what will be used for calling the function definition expression:
a) Function prototype
b) Function literal
c) Function calling
d) Function declaration
1.8 Which one of the following is used for the calling a function or a method in the JavaScript:
a) Property Access Expression
b) Functional expression
c) Invocation expression
d) Primary expression
1.9 Which one of the following operator is used to check weather a specific property exists or not:
a) Exists
b) exist
c) within
d) in
Category II
1.4 Discus the types of Java Script?
1.5 Explain arrays in Java Script?
1.6 Explain functions in Java Script?
PRACTICE:
Programs on JavaScript Control Statements, Arrays and Functions
<!-- Greatest of 2 numbers -->
<!doctype html>
<html lang="en">
<head>
<title>if-else statement</title>
<script language="javascript"
type="text/javascript" >
var a = window.prompt("Enter a number", "0");
a = parseInt(a);
var b= parseInt(prompt("Enter b number"));
if(a > b)
window.alert("The greatest is " +a);
else
alert("The greatest is " +b);
</script>
</head>
<body>
</body>
</html>
<body>
<script language="javascript" type="text/javascript" >
var a = parseInt(window.prompt("Enter Marks Sub1"));
var b= parseInt(prompt("Enter Marks Sub2"));
var c= parseInt(prompt("Enter Marks Sub3"));
var avg=(a+b+c)/3;
if(avg >= 70)
alert("First With Distinction");
else if(avg >=60 && avg <70) alert("First Class");
else if(avg >=50 && avg <60) alert("Second Class");
else if(avg >=40 && avg <50) alert("Third Class");
else alert("Fail");
</script>
</body>
</html>
switch(ch)
{
case 10:
case 9:
case 8:
case 7: window.alert("Distinction");
break;
case 6: window.alert("First Class");
break;
case 5: window.alert("Second Class");
break;
case 4: window.alert("Third Class ");
break;
default: window.alert("Fail ");
}
</script>
<body>
</body>
</html>
//switch statement Is fall-through
//switch allows string constant as case option
{
r= n % 10;
sum= sum+(r*r*r);
n=parseInt(n/10); //here n/10 float-> convert to int
}
document.writeln("The sum is " +sum);
if(sum == m)
</html>
document.write(n*i); document.writeln("<BR>");
}
</script>
</head>
<body> Multiplication Table
</body>
</html>
function fact( n )
{
var f =1;
for(var i=1; i<=n ; i++) f= f*i;
return f;
}
</script>
</head>
<body>
</body>
</html>
}
}
document.writeln("The elements after Sorting are <br>" );
for(var i=0 ; i < a.length ; i++)
document.writeln(a[i] + " " );
</script>
</head>
<body>
</body>
</html>
4 Advance scripting
1
V
UNIT SPECIFICS
Through this unit we will discuss the following aspects:
JavaScript and objects DOM and web browser environments.
Forms and validations in DHTML, AJAX it’s advantages & disadvantages.
XML It’s usage DTD and Schema.
XSLT and It’s Applications comparison with XML.
V
Introductory concepts of web Services.
RATIONALE
This unit focuses on the Java Script Objects both predefined and user defined objects.
Discussed DOM and various browser environments, like how to implement CSS, events,
and controllers such as buttons to make web page as Dynamic by embedding same to
HTML. It covers AJAX and it’s advantages and disadvantages, implementation of web
applications using AJAX.it also discuss the XML and it’s usage and DTD, SCHEMA and
XSLT and comparison of XML and XSLT and Introductory concepts of Web Servers.
PRE-REQUISITES
Problem Solving Skills
Object Oriented Programming
UNIT OUTCOMES
List of outcomes of this unit is as follows:
U4-O1: Explain Java Script Objects related to web Browsers
U4-O2: Describe the AJAX and it’s role to design the Web Application
58 | Advance Scripting
U4-O3: Explain the XML, DTD ,Schema implementation and it’s use .
U4-O4: Explain the XSLT and comparative study of XML and XSLT.
U4-O5: Describe the components of web services.
MA
4. JavaScript Objects
III. Math
IV. Number
V. Boolean
VI. Date
toUpperCase() The specified string is changed var str = " weCOME to HYD ";
to uppercase letters. document.writeln(str.toUpperCase());
string.toUpperCase()
lastIndexOf() It gives back the last place of the var web="Learn JavaScript on Javas
char value that was supplied to the cript";
method. document.write(web.lastIndexOf('a'));
lastIndexOf(ch)
It begins scanning the element var web="Learn JavaScript on Javasript"
from the given index value in ;
inverse order and then returns the document.write(web.lastIndexOf('a',10)
supplied char value's index );
position.
lastIndexOf(ch,index)
Web Technologies: Theory & Practicals | 65
dateObj.getDay()
getMonth() It gives back an integer var date=new Date();
value between 0 and 11 document.writeln(date.getMonth()+1);
that, based on local time, var date=new Date("July 8, 2019
reflects the month. 16:22:10");
document.writeln(date.getMonth()+1)
dateObj.getMonth()
dateObj.getSeconds()
getMilliseconds() It returns the milliseconds var milli =new Date();
based on local time as an document.writeln(milli.getMilliseconds());
integer value between 0 and var milli =new Date("July 8, 2019
999. 16:22:10");
document.writeln(milli.getMilliseconds());
dateObj.getMilliseconds()
setDate() It returns the milliseconds var d = new Date(); d.setDate(15);
based on local time as an
integer value between 0 and
999.(1 to 31)
setDate(dd);
Web Technologies: Theory & Practicals | 69
setFullYear(yyyy,mm,dd);
setMonth() On the basis of local time, it var d = new Date(); d.setMonth(11);
establishes the month value
for the supplied date.(0-11)
setMonth(mm)
setHours() Using local time, it var d = new Date(); d.setHours(22);
establishes the hour value
for the supplied date.
setHours(hh , mm , ss);
setMinutes() On the basis of local time, it var d = new Date(); d.setMinutes(30);
establishes the minute value
for the chosen date.
setMinutes(mm,ss)
setSeconds() On the basis of local time, it var d = new Date(); d.setSeconds(30);
sets the second value for the
provided date.
setSeconds(ss)
70 | Advance Scripting
The JavaScript Math object provides several constants and methods
to perform mathematical operation.
The Math object doesn't have constructors.
4.4.1. The methods of Date Object are
Math.cbrt(num)
ceil() It provides the least integer document.writeln(Math.ceil(7.2)); //8
result that is larger than or document.writeln(Math.ceil(0.2)); //1
equal to the inputted value. document.writeln(Math.ceil(-7.2));//-7
document.writeln(Math.ceil(-0.2)); //0
Math.ceil(num)
floor() The greatest integer value that document.writeln(Math.floor(7.2)); //7
is lower than or equal to the document.writeln(Math.floor(0.2)); //0
supplied number is returned.. document.writeln(Math.floor(-7.2));//-8
document.writeln(Math.floor(-0.2)); //- 1
Math.floor(num)
round() It returns the provided number's document.writeln(Math.round(7.2)); //7
closest integer value. document.writeln(Math.round(0.6)); //1
document.writeln(Math.round(-7.2));
Math.round(num) //-7
document.writeln(Math.round(-0.6));
//-1
Math.sin(num)
cos() It gives back the given number's document.writeln(Math.cos(1));
cosine.
Math.cos(num)
tan() It provides the provided document.writeln(Math.tan(1));
number's tangent back.
Math.tan(num)
sinh() It provides the provided document.writeln(Math.sinh(-1));
number's hyperbolic sine. document.writeln(Math.sinh(0));
Math.sinh(num)
Web Technologies: Theory & Practicals | 73
8)); document.writeln(Number.parseInt(
//octal value b));
//NaN
document.writeln(Number.parseInt(a,
16));
//hexa decimal value
parseFloat() It creates a floating point number from var b="50.25"
the provided string. var d="50.25String"
Number.parseFloat(string) document.writeln(Number.parseInt(
b));
document.writeln(Number.parseInt(
d));
toString() It returns the given number in the var n=new Number(16);
form of string. document.writeln(n.toString());
toString()
valueOf() valueOf() document.writeln(n.valueOf());
toExponenti It gives back a string that reflects the var a=989721;
al () provided number in exponential document.writeln(a.toExponential()
notation. ); 9.89721e+5
Number. toExponential(num)
boolean.valueOf()
Property Description
Name
closed determines whether a window has been closed by returning a Boolean
value.
default Status restores or sets the window's status bar's default text
document gives the window's Document object back.
history Returns the History object for the window
location Returns the Location object for the window
name Sets or returns the name of a window
Web Technologies: Theory & Practicals | 77
alert(message)
confirm() Displays a dialog box with a message confirm("Perform or not?");
and an OK and a Cancel button.
A confirm box is often used if you
want the user to verify or accept
something.
confirm(message)
prompt() Displays a dialog box that prompts the prompt("enter a no", "12")
visitor for input.
prompt(text, defaultText)
blur() Removes focus from the current myWindow.blur();
window. window.blur()
focus() Changes focus to the selected myWindow.focus();
window.
window.focus()
close() Closes the current window. myWindow.close();
window.close()
78 | Advance Scripting
Property Description
Name
length gives the number of URLs in the history list.
Web Technologies: Theory & Practicals | 81
Property Description
Name
appCodeName Returns the code name of the browser.
appName Returns the name of the browser
appVersion Returns the version information of the browser
cookieEnabled Determines whether cookies are enabled in the browser
platform Returns for which platform the browser is compiled
flag can be
4.13. Frames
HTML frames are used to divide the web browser window into multiple
sections, where each section can be loaded separately with a web page.
Frames allow you to view multiple pages on the same window at a time.
The element <frameset> is used to hold the collection of frames. This element
configures the frames on window/browsers.
A frameset is a collection of frames.
<Frame> tag is used to create frames.
<Frameset> element actually takes the place of <body> element in a document
that displays frames
<Frameset> allows to organise both vertical & horizontal frames, or both.
84 | Advance Scripting
X
<html>
<frameset cols = “ 25% ,*” bordercolor = “red”>
<frame name = “f1” src = “index.html”>
<frame name = “f2” src = “content.html”>
</frameset>
</html>
X
4.14.2. Program to Create the horizontal frames
<frameset rols = “27%, *”>
<frame name = “f1” src = “index.html”>
<frame name = “f2” src = “content.html”>
</frameset>
<html>
<head>
<title>named frames </title>
</head>
<body >
<frameset cols = “30% , *”>
<frame name = “f1” src = “index.html” >
<frame name = “f2” src = “content.html” >
</frameset>
</body>
</html>
Index.html
<html>
<body>
<a href = “cse.html” target = “f2”>cse</a>
<BR><a href = “ece.html” target = “f2”>ece </a>
</body>
</html>
“ if target = “new window” → displays the web page in a new window”.
88 | Advance Scripting
二
user controls
二
</form>
</body>
Clear
4.15.4. Adding a Reset Button:-
The reset button enables the user to erase all information input in text
fields, restore the form to its default state, and begin anew.
• The controls in the form revert to their initial state when the user clicks,
and the values in the fields are cleared.
Type value is “reset” in <input > tag
<input type = “reset” value = “clear”>
l
92 | Advance Scripting
• The user can click on a little box that has a check mark in it to choose or
clear it. Allows to select more options.
CE : < input type = “checkbox” name = “branch” value = “CE” >
CSE: <input type = “checkbox” name = “branch” value = “CSE” checked>
• The <form> tag's action URL and method are used to direct the form data to
the server.
action – The server's physical address, or URL, is where the user data is
forwarded.
When submit button clicked.
method – The attribute has two values get & post.
1. method = “ get “ —> indicates that the web browser must encrypt the
form data (by default) into a URL.
—> the form data visible in the address bar.
—> used for small forms.
Web Technologies: Theory & Practicals | 95
2. method = “ post “ —> indicates that the message body contains the
form data.
—> the form data invisible (hide)
—> used for large size forms.
—> Send data as a packet.
● In comparison to the limited usage of tags and attributes, style sheets offer a
mechanism to customise entire pages at once and in considerably greater detail.
● Style sheets provide tag and attribute based style to improve look feel of a
webpage.
● Style sheets are implemented with the Cascading Style Sheets (CSS)
specification.
● CSS is standardized by w3c, called CSS specifications.
● The CSS defines a rule with set of properties.
Ex : H1 { font-size : 20 pt }
Font-size —> property of css
20 pt —> value of css property .
● Style sheets are just a list of rules.
● The style sheets implementation varies from browser to browser
● The Styles are created by three ways.
1. Embedded style sheets (Internal style sheets)
2. External style Sheets
3. Inline style sheets
96 | Advance Scripting
The style attribute of every html tag is used to define the styles
Used to apply styles for a particular portion or to a particular element
Using inline styles, if several parts of the page adhere to the same style, all
styles must be specified repeatedly
If same styles are repeated in multiple parts of the webpage Embedded
Styles are used.
Embedded style sheets are for a webpage.
The styles applied throughout the webpage are collected and placed in one
place
Embedded styles are specified in < style > tag of < head > element.
Ex: < html >
Web Technologies: Theory & Practicals | 97
The < LINK > element in < head > tag is used to link css file for a webpage
“First.html “
< html >
< head >
< link href= “ demo.css “ rel = “ stylesheet “ >
< / head >
< body >
Welcome to Hyderabad
< a href = “ hyd.html “ > click here < /a >
< p > Hyd is for … < /p >
< /body >
< /html >
“Sec.html”
< html >
< head >
< link href= “ demo.css “ rel = “ stylesheet “ >
< / head >
< body >
Welcome to Secunderabad
< a href = “ Sec.html “ > click here < /a >
< p > Sec is for … < /p >
< /body >
< /html >
4.16.4. Style Classes
Enables the creation of styles as style classes in external or embedded style
sheets.
Assign the class attributes of an HTML element to the name of the style
class in order to apply a style specified in that style class to that HTML
element.
Web Technologies: Theory & Practicals | 99
<html>
<head>
<link rel = “stylesheet” href = “one.css”>
<link rel = “stylesheet” href = “two.css”>
<link rel = “stylesheet” href = “three.css”>
</head>
<body>
---------
---------
</body>
</html>
When multiple external styles sheets are used, cascading styles, a
combination of styles for different HTML elements, result.
If multiple files styles affect the same element, only the last one is used.
<pre>
Welcome to HYD
India is with Intellectual people
</pre>
<html>
<head>
<script language="javascript” type="text/JavaScript" >
function fun1()
{
var x = parseInt(document.f1.t1.value); var y =
parseInt(document.f1.t2.value); var z =
parseInt(document.f1.t3.value); var p = (x+y+z)/3;
document.f1.t4.value = p;
}
</script>
</head>
102 | Advance Scripting
<body>
<form name="f1" onreset="confirm('Would you like to clear')"
>
<center>
Marks in Sub1: <input type="text" name="t1" > <BR> <BR> Marks
in Sub1: <input type="text" name="t2" > <BR> <BR> Marks
in Sub1:<input type="text" name="t3" > <BR> <BR> Average
is :<input type="text" name="t4" > <BR> <BR>
<input type="reset" name="r1" value="clear" >
<input type="button" name="b1" value="FindAvg"
onclick="fun1()">
</center>
</form>
</body></html>
<!-- To send data through arguments to JavaScript function onclick and onreset --
>
<html>
<head>
<script language="javascript" type="text/javascript" >
function find(a , b ,c)
{ var x = parseInt(a); var y = parseInt(b); var z =
parseInt(c); var p = (x+y+z)/3;
document.f1.t4.value = p;
}
</script>
</head>
<body>
<form name="f1" onreset="confirm('Would you like to clear')"
>
<center>
Marks in Sub1: <input type="text" name="t1" id="m1" > <BR>
<BR> Marks in Sub1: <input type="text" name="t2" id="m2"
> <BR> <BR> Marks in Sub1:<input type="text" name="t3"
id="m3" > <BR> <BR> Average is :<input type="text"
name="t4" id="res" > <BR> <BR>
<input type="reset" name="r1" value="clear" >
Web Technologies: Theory & Practicals | 103
<html>
<head>
<script language="javascript" type="text/javascript" >
function fun1()
{
document.body.style.backgroundImage = "url('Jellyfish.jpg')"
}
function fun2()
{
document.getElementById("uname").focus();
}
</script>
</head>
<body onload="document.body.style.background ='#110022'"
onmousedown="fun1()"
onmouseup="document.body.style.background ='#EE1100'"
onmouseover="fun2()">
<form name="f1" >
<input type= "text" name="t1" id="uname" size=50> <br>
<input type="button" name="b1" id="100" value="click here"
onclick="alert(' Hi ' +
document.getElementById('uname').value)" ><br>
</form>
</body>
</html>
104 | Advance Scripting
<html>
<head>
<script language="javascript">
function fun1()
{
var x = document.getElementById("ch1").value;
alert("x value is " +x);
//returns on if no value field in checkbox. if selected
// returns the value field string of the checkbox
if(x=="cse")
{
document.writeln(" cse selected");
}
else
{
document.writeln(" cse Not Selected");
}
}
</script>
<body>
<form name="f1" >
<input type="checkbox" value="cse" id="ch1" onclick="fun1()"
> CSE
</form>
</body>
</html>
Web Technologies: Theory & Practicals | 105
<!DOCTYPE html>
<html>
<body>
<script language="javascript" type="text/javascript">
function fun1()
{
document.getElementById('male').checked = true;
document.getElementById('fem').checked = false;
document.getElementById("div1").innerHTML = "Gender
Selected " +"MALE";
}
function fun2()
{
document.getElementById('male').checked = false;
document.getElementById('fem').checked = true;
document.getElementById("div1").innerHTML = "Gender
Selected " +"FEMALE";
}
</script>
<form> Gender :
<input type="radio" id="male" onclick="fun1()"> MALE
<input type="radio" id="fem" onclick="fun2()"> FEMALE
</form>
<div id="div1" > </div>
</body>
</html>
4.17. AJAX
4.17.1. What is AJAX?
AJAX abbreviated as Asynchronous JavaScript And XML.
AJAX is not a language for programming.
AJAX exclusively employs a mix of:
• An integrated XMLHttpRequest object in the browser (to request data
from a web server)
JavaScript and DOM in HTML (to display or use the data)
• The name AJAX is deceptive. Although XML may be used by AJAX apps to
transfer data, plain text and JSON text are also frequently used.
106 | Advance Scripting
xmlhttp.onreadystatechange = function()
{
//Do something here
}
VI. Write a callback function to insert the data from the text file
into the h1 element when the state of the response changes.
xmlhttp.onreadystatechange = function() {
document.getElementById("page-
title").innerHTML = this.responseText; }
VII. Use the send() method to send the request.
xmlhttp.send();
The finished HTML page should look like this:
<html>
<head>
<title>An Ajax Web Application</title>
</head>
<body>
<h1 id="page-title"></h1>
<button id="load-data">Click Here to Load the Data</button>
<script>
document.getElementById("load-
data").addEventListener("click",function(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "data.txt");
xmlhttp.onreadystatechange = function() {
document.getElementById("page-title").innerHTML =
this.responseText;
};
xmlhttp.send();
});
</script>
</body>
</html>
Click the button on the HTML page after opening it in a browser. The script
will display the following output in a browser:
Web Technologies: Theory & Practicals | 109
4.18. XML
4.18.1. Introduction to XML
XML – Extensible markup language “XML is a markup language based on
simple, platform independent rules for processing and displaying textual
information in a structured way”.
i. Applications of XML:-
XML is used for various operations implementation
Configuring information
Publishing
Electronic data interchange
Voice mail system
Remote method invocation (RMI)
Object serialization
Vector graphics
XML is intended for transport or storage of data
Every XML document contains XML elements and attributes associated
with it.
110 | Advance Scripting
XML
HTML
It is used to describe, store and transport
It is used to display or present data. data.
Most of the tags are user defined.
Most of the tags are predefined
It is case sensitive
It is case insensitive language
Checks for syntax and rules.
It will not check for syntax or rules
It preserves the white spaces
It does not preserves white spaces
All the tags must have open and close
Some of the tags are not closed. i.e., tag.
both container and non-
container tag.
Web Technologies: Theory & Practicals | 111
<! ----
XML Documents
Rules + structure
Structure + data
+ Data
DTD (Document
Type Definition)
Schema
Web Technologies: Theory & Practicals | 113
Empty elements:-
An element may not have any content or nested elements in it.
Ex: <MIDDLENAME/>
<emps>
<emp>
<id prefix="INF">101</id>
<name>Ramesh</name>
<sal>85900</sal>
<dept grade="B"> Developer</dept>
<company><&address;></company>
</emp>
<emp>
<id>121</id>
<name>Suresh</name>
<sal>65900</sal>
<dept grade="C"> Tester</dept>
<company>"&address;"</company>
</emp>
<emp>
<id>131</id>
<name>Ganesh</name>
<sal>185900</sal>
<dept grade="A">Designer</dept>
<company>'&address;'</company>
</emp>
</emps>
<products>
<product>
<pid> LG102 </pid>
<pname> LG ULTRA HD 50 </pname>
<desc> High Definition </desc>
<price> 119000 </price>
<qty> 12 </qty>
</product>
124 | Advance Scripting
<product>
<pid> SS110 </pid>
<pname> SAMSUNG CURVE HD 50 </pname>
<desc> High UV Definition </desc>
<price> 139000 </price>
<qty> 8 </qty>
</product>
<product>
<pid> MI222 </pid>
<pname> MI CURVE HD 50 </pname>
<desc> High UV Definition </desc>
<price> 69000 </price>
<qty> 14 </qty>
</product>
</products>
<product>
<pid> SS110 </pid>
<pname> SAMSUNG CURVE HD 50 </pname>
<desc> High UV Definition </desc>
126 | Advance Scripting
<product>
<pid> MI222 </pid>
<pname> MI CURVE HD 50 </pname>
<desc> High UV Definition </desc>
<price> 69000 </price>
<qty> 14 </qty>
</product>
</products>
<catalog>
<motorbike>
<make> HeroHonda</make>
<model>PassionPro</model>
Web Technologies: Theory & Practicals | 127
<year> 2019</year>
<color>Black</color>
<engine>
<eng-no> 2345EF</eng-no>
<cylinders>2 </cylinders>
<fueltype> Petrol</fueltype>
</engine>
<chasisnum>1122</chasisnum>
<accessories diskbrake="yes" autostart="no"> ALL Reuired ,
&mirror;</accessories>
</motorbike>
<motorbike>
<make> Honda Active</make>
<model>5G</model>
<year> 2018</year>
<color>RED</color>
<engine>
<eng-no> 12345EF</eng-no>
<cylinders> 4 </cylinders>
<fueltype> Petrol</fueltype>
</engine>
<chasisnum>110022</chasisnum>
<accessories diskbrake="yes" autostart="yes"> ALL Reuired
, &mirror;</accessories>
</motorbike>
</catalog>
Ex: <student>
<BTECH>
128 | Advance Scripting
Here would be a name conflict for <course> and <age>, but the elements
have different content and meaning.
Name conflicts in XML can easily be avoided using a name prefix.
<student xmlns:ug="http://www.w3.org/2001/XMLSchema"
xmlns:pg="http://www.w3.org/2001/XMLSchema" >
<BTECH>
<ug:course> Computer Science </ug:course>
<ug:age> 22 </ug:age>
</BTECH>
<MTECH>
<pg:course> DataScience </pg:course>
<pg:age> 24 </pg:age>
</MTECH>
</student>
4.18.5. XML Schema
An XML document's structure is represented by an XML Schema.
The constituent parts of an XML document are defined using an XML
schema.
Another name for the XML schema language is XML Schema Definition
(XSD) language.
In 2001, W3C recommended it.
Similar to a DTD, an XML Schema explains the structure of an XML
document.
A properly formatted XML document is referred to as "Well Formed."
• An XML document is "Well formed" and "Valid" if it has been validated
against an XML Schema".
Elements, properties, and child elements are defined by XML Schema..
Furthermore, it specifies the fixed and default values for components and
attributes.
Web Technologies: Theory & Practicals | 129
i. Simple Types:
An element has no child elements or attributes; it just has a
value.
Simple type elements are only used in conjunction with text.
• The <xs:simpleType> tag is used to generate the simple type
element.
Ex: <age> 30 </age>
<xs:simpleType name=”age” type=”xs:integer”/>
ii. Complex Types
Child elements and attributes are part of an element.
A complicated type serves as a holding area for additional
element definitions. By doing so, you may give your XML
130 | Advance Scripting
Ex: <address>
<name> Infosys </name>
<company> Hyderabad </company>
<phone> 1234056789 </phone>
</address>
,< <xs:element name = "address">
<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string" />
<xs:element name = "company" type = "xs:string" />
<xs:element name = "phone" type = "xs:integer" />
</xs:sequence>
</xs:complexType>
</ <xs:element>
The XML Schema uses various indicators to control how the elements
can be used in XML document.
i. Order Indicators.
used to specify the document's XML elements' order.
ii. All indicator
The <all> indicator states that each child element must only
appear once and that it can appear in any sequence.
• When using the <all> indication, the "minOccurs" indicator
can be set to 0 or 1, but the "maxOccurs" indicator can only
be set to 1.
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
iii. Choice Indicator
The choice> indicator indicates that just one of the child
elements may occur.
<xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="string"/>
<xs:element name="member" type="string"/>
Web Technologies: Theory & Practicals | 133
</xs:choice>
</xs:complexType>
</xs:element>
iv. Sequence Indicator
The < sequence> indicator dictates the order in which the
child elements must appear.
<xs:element name="emp">
<xs:complexType>
<xs:sequence>
<xs:element name="eid" type="xs:string"/>
<xs:element name="ename" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
v. Occurrence indicators.
The frequency of an element can be determined using the
Occurrence indicators.
For both maxOccurs and minoccurs, the default value is 1.
vi. maxOccurs Indicator
• The maximum number of times an element may occur is
specified by the <maxOccurs> indication.
maxOccurs=”unbounded” specifies any number of elements
included.
The meta characters
* => minOccurs=0 , maxOccurs=”unbounded”
o + => minOccurs=1 , maxOccurs=”unbounded”
? => minOccurs=0 , maxOccurs=”1”
o
vii. minOccurs Indicator
V. Element groups
The group declaration defines element groupings.
<xs:group name="groupname">
...
</xs:group>
Ex:
<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Ex:
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="prefix" type="xs:string"/>
<xs:attribute name="grade" type="xs:string"/>
</xs:attributeGroup>
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
<xs:enumeration value="IT"/>
<xs:enumeration value="ECE"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
ii. Restrictions on a Series of Values
To limit the content of an XML element to define a series of
numbers or letters that can be used.
We would use the pattern constraint.
<xs:element name="ename">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([A-Z])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:restriction base="xs:string">
<xs:length value="8"/> //exact no.of
chars
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/> //minimum
no.of chars
<xs:maxLength value="8"/> //maximum
no.of chars
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
Web Technologies: Theory & Practicals | 139
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1"
maxOccurs="1"/>
<xs:element name="author" type="xs:string" minOccurs="1"
maxOccurs="1"/>
<xs:element name="publisher" type="xs:string"
minOccurs="1" maxOccurs="1"/>
<xs:element name="pages" type="xs:integer" minOccurs="1"
maxOccurs="1"/>
<xs:element name="price" type="xs:decimal" minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="course" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
<book course="cse">
<title> Operating Systems </title>
<author>Galvin</author>
<publisher>TMcH</publisher>
<pages>900</pages>
<price>850.50</price>
</book>
<book course="ece">
140 | Advance Scripting
4.19. XSLT
4.19.2. Advantages
The advantages of using XSLT are:
Not dependent on programming. Transformations are written in a separate
XSL file, which is itself an XML document.
• The transformations in the xsl file can be changed to change the output.
No codes should be changed. Hence, web designers can alter the CSS and
rapidly see the results of their changes.
• Formatting is accomplished with HTML tags. These will not be processed
by XSLT, and the browser will just render them.
• <xsl:stylesheet> - XSL stylesheet declaration utilising an XSL namespace:
Namespace informs the XLST processor which elements are utilised
exclusively for output and which ones must be processed.
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template> - template tells the xlst processor about the section of xml
document which is to be formatted. It takes an XPath expression. In
general, it is matching document root element and will tell processor to
process the entire document with this template.
Defines a way to reuse templates in order to generate the desired output
for nodes of a particular type/context.
<xsl:template match = "/">
<xsl:value-of> tag puts the value of the selected node as per expression as
text.
<xsl:value-of select = "firstname"/>
<xsl:for-each> tag applies a template repeatedly for each node. processing
instruction looks for each element matching the XPath expression
<xsl:for-each select = "class/student">
<xsl:sort> tag specifies a sort criteria on the nodes.
<xsl:sort select = "firstname"/>
<xsl:if> tag specifies a conditional test against the content of nodes.
<xsl:if test = "marks > 60">
The <xsl:choose> tag, in conjunction with the <xsl:otherwise> and
<xsl:when> elements, specifies a number of conditional checks against the
content of nodes.<xsl:choose>
142 | Advance Scripting
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
Web Technologies: Theory & Practicals | 143
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
</catalog>
//mystyle1.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<table align="center" border="1">
<caption> <h2>Books Information</h2></caption>
<tr bgcolor="#BBEEFF">
<th style="text-align:left">Title</th>
<th style="text-align:left">Author</th>
<th style="text-align:left">Publication</th>
<th style="text-align:left">Edition</th>
<th style="text-align:left">Price</th>
</tr>
<xsl:for-each select="catalog/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of
select="publication"/></td>
<td><xsl:value-of select="edition"/> </td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
144 | Advance Scripting
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
//studstyle.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<html>
<body>
<h2>Students</h2>
Web Technologies: Theory & Practicals | 145
<xsl:for-each select="class/student">
<tr>
<!-- @ is used to access attribute -->
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
//selecting data based on condition (if)-stud.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Marks</th>
</tr>
</table>
Web Technologies: Theory & Practicals | 147
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "marks"/></td>
<td>
<xsl:choose>
<xsl:when test = "marks >= 70"> Distinction
</xsl:when>
<xsl:when test = "marks >= 60" > First
</xsl:when>
<xsl:when test = "marks >= 50" > Second
</xsl:when>
<xsl:otherwise> Fail
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
148 | Advance Scripting
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
● Applications written in Java,.NET, and PHP can connect with one another across
a network using web services, as shown in the image.
Web Technologies: Theory & Practicals | 149
● The Java application, for instance, can communicate with Java,.Net, and PHP
programmes. Web services are a language-neutral form of communication.
Unit Summary
Through this unit we have learnt about JavaScript and objects, DOM and web browser
environments. We have also understood Forms, validations in DHTML, AJAX, it’s advantages
& disadvantages. In addition we have delved into XML, It’s usage, DTD and Schema, XSLT and
It’s Applications, comparison with XML and Introductory concepts of web Services.
EXERCISE
Multiple Choice Questions
1.1 JavaScript objects can be created with the new keyword, and with the ………………. function.
a) object()
b) object.create()
c) JavaScript.object()
d) create.object()
1.2 A ……………………. object is any object created by the execution of JavaScript code.
a) native
b) host
c) user defined
d) remote
1.3 What will be printed in the console on execution of the following JS code:
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
var myArr= array.filter(v => v % 3 === 0);
console.log(myArr);
a) myArr
b) [3, 6, 9, 12, 15]
Web Technologies: Theory & Practicals | 153
1.6 If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the
paragraph?
a) "New Text"?
b) para1.value="New Text";
c) para1.firstChild.nodeValue= "New Text";
d) para1.nodeValue="New Text";.
1.7 JavaScript provides a special constructor function called Object() to build the object.
a) TRUE
b) FALSE
c) Can be true or false
d) Can not say
1.10 ____is used to read XML documents and provide access to their content and structure.
a) XML Processor
b) XML Pre-processor
c) XML Compiler
d) XML Interpreter
1.11 Which is the correct XML declaration?
a) <xml version="1.0" encoding="UTF-8"/>
b) <xml version="1.0" encoding="UTF-8"></xml>
c) <?xml version="1.0" encoding="UTF-8"?>
d) <?xml type="document" version="1.0" encoding="UTF-8"?>
1.20 The basic Web Services platform is combination of _____ and _______
a) CSS + HTTP
b) XML + HTML
156 | Advance Scripting
c) XML + HTTP
d) CSS + JAVA
1.11 Write a JavaScript program to get the width and height of the window (any time the window is
resized).
1.12 write a html program to control the background repetition of the image with background repeat
property.
1.13 Write a program to perform client side validation in the following fields.
1. Username(should at least 6 characters)
2. Password(should at least 8 characters)
Web Technologies: Theory & Practicals | 157
3. Mobile number
4. E-mail
1.14 Write a XML document to display the book information which includes the following XSL.
1. Title 2. Author 3. Publisher 4. Price 5. ISB number
1. Web Technologies: HTML, JAVASCRIPT, PHP, JAVA, JSP, XML and AJAX, Black Book
by Kogent Learning Solutions Inc. | 28 November 2012
2. HTML 5 Black Book, Covers CSS 3, JavaScript, XML, XHTML, AJAX, PHP and jQuery, 2ed
by DT Editorial Services | 1 January 2016
3. Head First JavaScript Programming: A Brain-Friendly Guide by Elisabeth Robson and Eric
Freeman | 1 January 2014
4. XML: The Complete Reference by Heather Williamson | 9 July 2001
5. XSLT [Book] (oreilly.com)
6. J2EE™ Web Services, 1e by HAEFEL | 1 January 2004
5 PHP
UNIT SPECIFICS
Through this unit we will discuss the following aspects:
Server-side scripting.
Advance PHP Databases.
Inserting and data by Connecting Server.
Listing, Altering and Deleting Databases and Tables.
PHP myadmin and database bugs.
RATIONALE
This unit focuses on the server-side scripting and constructs in PHP like Arrays,
functions and forms. Advanced PHP Databases will be explained by various example
programs such as Connecting to the server with connection objects and discussed how
to handle the situations where connection object is not established. mostly focuses on
building databases, choosing databases, listing databases, listing table names, creating
tables, adding data, changing tables, queries, deleting databases, deleting data, and
deleting tables. flaws in PHP's myadmin and databases.
PRE-REQUISITES
Problem Solving Skills
Object Oriented Programming
UNIT OUTCOMES
List of outcomes of this unit is as follows:
U5-O1: Explain Server-side Scripting
U5-O2: Explain advanced PHP Databases
U5-O3: Explain the PHP Database Creation, Selecting and Listing.
U5-O4: Explain the PHP Table creation, inserting data into tables and deleting tables.
U5-O5: Describe the PHP myadmin and database bugs.
Web Technologies: Theory & Practicals | 159
5. Introduction to PHP
PHP - (Hypertext preprocessor) is a server side scripting language used to create
dynamic webpages. Create dynamic webpages.
Originally called personal Home page
The various version of PHP are PHP version 2 – PHP version 6 (current)
PHP scripts run on a server.
PHP is a free and open-source programme.
160 | PHP
VII. Access logging – allows you to keep track of how often a website or page is
accessed. Additionally, it assists in creating the footer that displays access
information on every page.
VIII. Safe mode Support – allows several users to run PHP scripts concurrently on
the same server. solves the security issue with shared servers.
IX. Open source – enables the user to work with many programming
languages. The user can select a language to write their own source code for
various applications and release it for free online.
X. Third part application support - includes a common API for database access
and supports a large variety of various databases.
XI. PHP Extensible Architecture – allows users to send and receive emails using
the SMTP Internet protocol in a variety of file formats, including GIF, JPEG,
and PNG. access to Java classes, C libraries, etc.
XII. Dynamic typing - PHP does not require declaring variables. Only when a
variable is assigned a value does its type become set.
XIII. Large no.of library functions - To write efficient PHP code.
5.3. Advantages of PHP over other scripting languages.
I. Active server pages (ASP) – support by only Microsoft IIS. (Internet
Information server (IIS) used only for win 32 (windows) systems. ASP is much
slower, less stable & less secure.
II. Supported by almost all the web servers. Works with apache, proven record
of speed, reliability & secure.
III. Cold Fusion - Available only for win32, Solaris, Linux 7 HP, designed for the
non-programmers, focused on programmers. Compared with cold fusion
faster, more efficient & stable language.
IV. Perl (Practical Extraction & Reporting language) - Relatively PHP is Easier to
integrate with HTML, easy to learn & has smaller learning curve. No prior
knowledge of programming required. Perl is for complex tasks, more
complicated.
V. JSP (java server pages) - PHP is supported for all platforms, that is equal or
above 32 bits. But JSP is supported by only those platforms that have a JVM.
Performance of PHP is 5 times faster than JSP.
162 | PHP
5.7.3. String Operators (.): The dot (.) is a string concatenation operator is
used to combine values to create a string. Build a string from other
strings, variables and numbers.
Ex: 1) $str = “Hyderabad”;
echo ‘my city is’ .$str;
2) $echo ‘my city is ‘. ‘hyd’;
5.7.4. Comparison operators: Used to compare one value with another and
returns true or false based on status of the match.
== Equal to
!= Not equal to
<> Not equal to
168 | PHP
=== Identical to
!== Not identical to
< Less than operator
> Greater than operator
<= Less than or equal to operator
>= Greater than or equal to operator
5.7.5. Logical Operators: Also called Boolean operators, evaluates the logical
expression and return true or false.
Associativity operators
Right ! Logical
Left *, /, % Arithmetic
Left +, -, . Arithmetic & string
Left & Bitwise, references
Left | Bitwise
Web Technologies: Theory & Practicals | 169
do {
statements
} while (condition);
Statement;
}
5.9.3. Jump statements
break
continue
exit -- used when we want to stop a program from running. It can block
infinite looping statements in the program.
Ex: for($k=0; $k<5;$k++)
{
If($k==3)
{
exit;
}
echo “ the no is “.$i;
echo “<br>;
}
echo “ this is exit”;
5.10. Arrays:
An array is a homogeneous collection. Array elements are accessed by
name and index.
Ex: $cities = array (‘hyd’, ‘KMNR’,’VJW’);
echo “the second name is $cities [1]”;
PHP supports 3 types of arrays
5.10.1. Numeric array (indexed array)
Defines an array with a numeric ID key (index). The index value starts from
‘0’. The array can store number, string, object etc. the integer values as
their index.
Ex: <?php
$cities =array (“hyd”, “Chennai”,”delhi”,”bopal”);
print_r($cities);
?> ex: $cities [2]
print_r () – It is a built in function in PHP, used to print or display
information stored in a variable.
172 | PHP
print_r ($variable)
print_r ($variable, $flag)
if flag is true, the result is stored into a variable, rather than printing. By
default flag is false, flag is optional.
Ex: $cities = array(“hyd”, “ooty”, “delhi”);
print_r($cities);
$res = print_r($cities, true);
echo “$res”;
5.10.2. Associative Arrays
In associative arrays, an index is associated with a value.
Ex: employee name – key
Salary – value.
The values are accessed by specifying key.
Ex: $sal = array(“Teja” => 35000, “ravi”=>60000,”sahithi”=>45000);
(OR)
$sal [“Teja”] => 35000;
$sal [“ravi”] => 60000;
$sal [“sahithi”] => 45000;
5.10.3. Multidimensional Arrays
A multidimensional array is an array of arrays. I.e. A array can contain sub
array, it further has sub array and so on.
Ex: $emps = array(array (“ram” =>87000, “suresh”=>
97000, “ganesh”=>99000), array(“rajesh”=> 165000,
yakub”=>11500),
array(“raman”=>45000,”harish”=>35000));
print_r($emps);
//code to execute
return expn;
}
A function is declared using ‘function’ keyword.
Ex:
<? php
function find ($m, $n, $c=10, $d=5)
{
Return ($m+$n+$c+$d);
}
$x = find (10, 20); // 10+20+10+5
$y = find (10, 20, 30); // 10+20+30+5
$z = find (10, 20, 30, 40); // 10+20+30+40.
?>
B. $_POST [ ] function:-
The built-in function $_POST [] is used to get values from a form
supplied using the post () method.
Ex: 1) <? php echo $_GET [“name”]; ? >
2) <? php echo $_POST [“name”]; ?>
C. $_REQUEST [ ] function:-
Applied to the gathering of form data transmitted via the get ()
and post () methods.
Ex: <? php echo $_REQUEST [“name”]; ? >
D. $ SERVER [‘REQUEST_METHOD’]:-
Which methods (get or post) used by the form to send data to the
server is know from this SERVER method.
Ex: <? php
if ($SERVER [‘REQUEST_METHOD’] == ‘get’)
Web Technologies: Theory & Practicals | 177
Open the phpMyAdmin interface by starting the Apache server and going to
localhost/phpmyadmin in a web browser.
Since we set up a MySQL database during the Environment Setup, we have a root user with the
password root@123. You must provide the same credentials once phpMyAdmin
has opened in order to access the database.
5.14.4. Dashboard
The following sections are loaded on the phpMyAdmin screen once you have logged in.
The left-hand section displays the databases that are accessible, including both
system- and user-created databases.
Web Technologies: Theory & Practicals | 183
The dashboard's right side displays a tabbed interface for doing all database management
tasks, as seen below.
184 | PHP
`
Web Technologies: Theory & Practicals | 185
5.14.5. Databases
To view a list of databases with additional information, select the Database tab. Here, we
may perform various activities including database creation and database iteration.
To view a list of tables with additional information, click on any mentioned database.
According to the context, tabs alter. Now, tabs will display according to the
database.
186 | PHP
Web Technologies: Theory & Practicals | 187
5.14.6. Tables
Click on any table in the schema browser right now to bring up its details and use the
redesigned tabbed interface to perform the procedures outlined below on that table.
−
Any cell that has been double clicked becomes editable, allowing you to change and save
data. The esc key has no effect on data saving. The update query and operation
status will be displayed as soon as you exit the editing cell, as seen below.−
188 | PHP
You can confirm the update statement by using the links below.
5.14.7. Bugs-Debugging
Rarely do programmes function properly on the first try. Numerous issues in your
software could result in the PHP interpreter producing an error message. The
location of the error messages is up to you. Messages may be transmitted to the web
Web Technologies: Theory & Practicals | 189
browser together with other application output. They may be recorded in the web
server error log as well.
The display errors configuration directive must be set to On in order for error messages to
appear in the browser. Set log errors to On to send errors to the web server's error
log. If you want error warnings in both places, you can turn them both on.
When setting the value of error reporting in PHP, you can utilise some defined constants
to ensure that only specific kinds of errors are reported: E_ PARSE (parse errors),
E_ ERROR (fatal errors), E_ WARNING (warnings), E _NOTICE (notices), and E
_STRICT are the error codes that can be used (strict notices).
Use PHP-aware editors for creating your PHP application, such as BBEdit or Emacs.
Syntax highlighting is one of these editors' unique characteristics. Depending on
what those components are, it alters the colour of those areas in your programme.
Strings are pink, whereas words like "if" and "while" are blue, "comments" are
grey, and "variables" are black, as examples.
Another feature that ensures the balance of your quotations and brackets is quote and
bracket matching. The editor highlights the opening delimiter that it matches when
you input a closing delimiter like.
The following points need to be verified while debugging the program.
Missing Semicolons − A semicolon is used to end each PHP statement (;).
A semicolon is the point at which PHP halts its reading of a statement.
PHP continues reading the statement on the following line if you don't use
a semicolon at the end of a line.
Not Enough Equal Signs − Two equal signs (==) are required when
determining whether two values are equal in a comparison statement. One
common error is to only use one equal sign.
Misspelled Variable Names − PHP interprets a misspelt variable as a
brand-new variable. Keep in mind that $test and $Test are not the same
variables in PHP..
Missing Dollar Signs − Although it can be quite difficult to spot, a
missing dollar sign in a variable name normally results in an error message
that lets you know where the issue is.
Troubling Quotes − It's possible to use too many, too few, or the incorrect
kinds of quotations. So make sure there are a fair quantity of quotes.
Missing Parentheses and curly brackets − They should always be in
pairs.
Array Index − All the arrays should start from zero instead of 1.
190 | PHP
Additionally, handle all problems appropriately and direct all trace messages to the
system log file so that, in the event that a problem arises, it will be recorded there and
you can troubleshoot it from there.
Unit Summary
Through this unit we have understood Server-side scripting, Advance PHP Databases and
Inserting data by Connecting to Server. We have also learnt Listing, Altering and
Deleting Databases and Tables. In addition we have also delved into PHP myadmin and
database bugs.
EXERCISE
1.3 Which of the following function displays the information about PHP and its configuration?
a) php_info()
b) phpinfo()
c) info()
d) None of the above
1.4. Which of the following is the correct syntax to write a PHP code?
a) <?php ?>
b) < php >
c) < ? php ?>
Web Technologies: Theory & Practicals | 191
d) <? ?>
1.7 Which one of the following databases has PHP supported almost since the beginning?
a) Oracle Database
b) SQL
c) SQL+
d) MySQL
1.8 The updated MySQL extension released with PHP 5 is typically referred to as _______________
a) MySQL
b) mysql
c) mysqli
d) mysqly
1.10 Which method returns the error code generated from the execution of the last MySQL function?
a) errno() b) errnumber()
c) errorno() d) errornumber()
192 | PHP
The best way to learn Web technologies is by trying out programmes yourself. Following
are certain references which I have found useful. There must be other numerous
resources as well.
[1] HTML and CSS: Design and Build Websites by Jon Duckett
[2] Learning Web Design: A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics by
Jennifer Niederst Robbins
[3] Web Development and Design Foundations with HTML5 by Terry Felke-Morris
[4] JavaScript and jQuery: Interactive Front-End Web Development by Jon Duckett
[5] HTML5 and CSS3: Responsive Web Design Cookbook by Benjamin LaGrone
[6] Responsive Web Design with HTML5 and CSS: Develop future-proof responsive websites
using the latest HTML5 and CSS by Ben Frain
[7] Mastering Web Application Development with AngularJS by Pawel Kozlowski
[8] Node.js Web Development, 4th Edition by David Herron and Brad Dayley
[9] Flask Web Development: Developing Web Applications with Python by Miguel Grinberg
[10] The Complete Guide to Web Development for Beginners by Arianne Dee
194 | Index
Course outcomes (COs) for this course can be mapped with the programme outcomes (POs) after
the completion of the course and a correlation can be made for the attainment of POs to analyze
the gap. After proper analysis of the gap in the attainment of POs necessary measures can be
taken to overcome the gaps.
The data filled in the above table can be used for gap analysis.
Web Technologies: Theory & Practicals | 195
INDEX
H
HTML 35
A History Object 80
Arrays 40 HTML Forms 87
AJAX 106 HTML Controls 87
B I
Boolean 75 Indexes 24
Building blocks 21
J
C JavaScript 35
Cache 22
Client side scripting 35 L
Control Statements 39 Load balancers 25
Cascading style sheets(CSS) 95 Location Object 81
Control Structures 171
M
D Math Object 70
Dynamic IP 7
Date Object 66 N
Document Object 78 Number Object 73
E O
Embed 37 Operator 39
Objects 58
F
Function 40 P
Frames 83 Proxies 23
PHP 160
G
Grouped content 10
196 | Index
Q W
Queues 25 Web program 3
Web application 4
S Web Development 5
Secure connection 4 Web browser 6
String Object 62 Web server 6
screen Object 82 Web designing 7
Web Application architecture (WAA) 26
V
Variables 163 X
XML 110
XSLT 141
Web Technologies: Theory & Practicals | 197