Professional Documents
Culture Documents
Unit 1
Unit 1
Structure
1.1
Introduction
Objectives
1.2
1.3
1.4
1.5
1.6
1.7
1.8
Summary
1.9
Glossary
1.10
Terminal Questions
1.11
Answers
B2016
Page No. 1
1.1
Unit 1
Introduction
The Internet has impacted our life in numerous ways. It has changed the
way we work, communicate, network, educate ourselves and others, make
financial transactions, and much more. It offers many possibilities and is an
empowering tool.
This experience of getting online is facilitated by the World Wide Web
(www), commonly known as the web. The web is a structure of interlinked
documents called web pages accessed through the Internet. Web pages
contain images, text, videos, and many other multimedia elements. The
multiple multimedia elements that the web offers are enabled by web
applications. Web applications are programs that run on more than one
computer and communicate through a network or server.
Virtually every type of web application is developed and delivered by using
Java. Java is a programming language that allows the programmers to
develop high-performance applications such as mobile applications, web
applications, and enterprise applications. As a programming language, Java
is the global standard for developing and delivering web applications. Java
programs can be embedded in web pages and distributed to users. This
facilitates automatic distribution and installation of applications on the
computer.
In this unit, you will learn about the web, Java and the role and importance
of Java in web designing and development. First, you will get an overview of
the web. Next, you will be introduced to Java as a programming language.
Further, you will learn about Java based web technologies such as Servlets
and Java Server Pages or JSPs. Towards the end of the unit, you will learn
about web architecture models.
Objectives
After completing this unit, you will be able to:
B2016
Page No. 2
Unit 1
1.2
The World Wide Web or the web is an information sharing model for
accessing information on the Internet. The web and internet are not the
same; they are separate but related. The Internet is a network. It enables
the user of any computer connected to the Internet to retrieve information
from other computers connected to the Internet, provided the user has
permission to do so.
With the passage of time, the Internet has gradually evolved into its present
form. In 1969, Advanced Research Projects Agency (ARPA) of the U.S.
government realised that in the interest of a proper research and
development in the country, research scientists at one university must be
able to communicate with the scientists at other universities. This realisation
on part of the government led to the development of a network called the
Advanced Research Projects Agency Network (ARPANET). ARPANET
allowed the research scientists and scholars from different universities to
communicate with each other. One of the benefits of ARPANET was that
the network could function properly even if a portion of it was destroyed.
ARPANET finally evolved into the Internet, which is a public, cooperative,
and self-sustaining network, allowing people to communicate worldwide.
The web was developed by Tim Berners-Lee of the European Organization
for Nuclear Research (CERN) in Switzerland in 1989. Initially, the web used
networked hypertext documents to allow effective communication among
the members worldwide. Then, the hypertext documents over the web
began to include graphics, video, and sound. Due to the effective and
proper communication provided by the web, its use has spread globally in
an amazingly shorter period of time. The significance of Berners-Lee's
invention lies in the fact that it integrated hypertext to the Internet and
developed the following three technologies:
1.
Universal
Document
B2016
Page No. 3
Identifier (UDI)
Unit 1
2.
3.
HyperText
Transfer
Protocol
(HTTP)
2.
B2016
Page No. 4
Unit 1
a. 1969
b. 1979
c. 1989
d. 1999
3.
4.
Which of the following statements are correct about the World Wide
Web?
a. It requires unidirectional links
b. It requires bidirectional links
c. It marries hypertext to the Internet
d. It is non-proprietary
Activity 1:
Make a comparative list of features of the World Wide Web and some of
its predecessors.
Objective of the activity: To enhance your understanding of the superior
features of the World Wide Web
This activity should not take you more than 10 minutes to complete.
1.3
A web browser is the application software that allows users to access and
navigate the World Wide Web. A web browser allows the users to make
request to the web server for a particular task, which is then processed by
B2016
Page No. 5
Unit 1
the server and the desired result is sent to the web browser. The types of
web browsers can be classified under the following categories:
Graphical: Such web browsers allow you to access text, images, audio,
and video present in documents over the web. Examples of such web
browsers are Internet Explorer, Firefox, Apple Safari, Google Chrome and
Netscape. These web browsers are available for Windows, Mac, Linux and
other operating systems. Usually, navigation of web pages or links in the
Graphical web browsers is done by using a mouse pointer. Although you
can install a graphical web browser on your computer, yet some of these
browsers are automatically installed during the installation of the operating
system. For example, Internet Explorer is a part of the Windows operating
system, and can also be downloaded and installed using the
http://www.microsoft.com/ URL. Firefox is the web browser that can be
downloaded from the http://www.mozilla.org/products/firefox/ URL and
Safari is available at the http://www.apple.com/safari/ URL. Fig. 1.1 shows
different graphical web browsers:
Text: Such web browsers allow you to access the documents over the web
in text-only mode. Navigation in the text type web browser is done by
highlighting emphasised words using the up and down arrow keys, and then
pressing the ENTER key to open the link. Lynx is a good example of a text
web browser.
1.3.1
B2016
Page No. 6
Unit 1
Refresh button
Back
button
Navigation Toolbar
Home button
Workspace
Scroll
Status bar
Bars
B2016
Page No. 7
1.3.2
Unit 1
Easy to Use
Component
Rich
Caching
Features
of Web
browsers
Search
Bookmark
Complete
Internet
Package
B2016
Page No. 8
Unit 1
URL stands for Uniform Resource Locator, which defines the unique
Internet address of a file stored on a host computer connected to the
Internet. Every Internet resource possesses a unique URL, irrespective of
the fact that whether or not it can be accessed by a user. You can access a
web page or any other resource available on the Internet by providing the
appropriate URL of the resource in the web browsers; for instance, the URL
to access the web page of Google is http://www.google.com. A specified
URL helps access the appropriate resource from the specific directory
available on the host computer. This resource is then displayed on the
monitor of the clients machine. The process of providing a unique name to
a resource or domains is known as DNS.
The DNS is a worldwide system of servers that contains pointers to the
websites. DNS provides alphanumeric addresses (URL) that can be easily
remembered by the users. The concept of alphanumeric addresses has
eased the problems of users as now they do not have to remember the
numeric Internet Protocol (IP) address of the hosts. The alphanumeric
addresses are automatically translated into the specific IP address and the
desired file stored at that IP address is retrieved.
B2016
Page No. 9
Unit 1
For example, the URL of the website of the U.S. House of Representatives
(http://www.house.gov/house/House_Calendar.shtml) represents addresses
hosted in domains in the United States.
Fig. 1.4 explains the components of this URL:
Some commonly used top-level domains (TLDs) are defined in Table 1.1:
Table 1.1: Commonly Used TLDs
.com
.edu
.net
.org
in
India
ch
China
de
Germany
jp
Japan
B2016
Page No. 10
Unit 1
uk
United Kingdom
ca
Canada
Lets now learn the concept of Hypertext Transfer Protocol (HTTP) that is
used to transfer data over the web.
Overview of HTTP
The data on the web is transmitted by using some specific protocols. The
main protocol used for the web is HTTP, which defines how the computers
on the web or Internet exchange data. The HTTP defines how the web
browser and the web server can communicate with each other, while the
TCP and IP protocols perform the actual task of moving bits and bytes over
the network. An HTTP conversation consists of a handful of commands from
the client and a stream of data from the server.
Fig. 1.5 shows the flow of data exchange on the Internet:
When a client makes request to a web server using a web browser, the browser
contacts and sends the user request to the server.
Then, the web server processes the request and delivers the response generated in
the form of a document to the client.
The web browser at the clients end displays the received document or response.
The server also informs the web browser about the kind of document. It specifies
whether the document is an HTML file, a PDF file, or a ZIP file.
The document is displayed in the appropriate program in accordance with the type
of the document received by the web browser. For example, if the PDF file is
returned by the web server in the form of the response, then the file is displayed
with the help of the Adobe Reader program installed on the clients machine.
B2016
Page No. 11
Unit 1
NOTE:
A software program that retrieves document from the web server is
referred to as a client in network terminology and as a user agent in web
terminology. Also, the computer responding to the clients request is
known as server and not the computer.
Lets now understand the concept of cookies that are meant for
remembering user information.
Cookies
A cookie is a text file that is stored on the clients computer by a web server.
Cookies can be retrieved later by the web server whenever the client makes
the request again to the server. A unique ID number may be generated for
each visitor by a website that can be stored by it on every clients machine
using a cookie file.
If you are using the Microsoft Internet Explorer for browsing the web, all the
cookies files get stored on your machine in the cookies folder. You can find
this folder in the Documents directory of the current user. When you
navigate to the Cookies directory on your machine you would find many text
files (Cookies file).
Cookie files contain information in the form of name-value pairs. On the
basis of the name and value pair, you can easily identify the website that
placed the cookie file on your machine. When you access a website, say,
www.google.com,it places a cookie file on your machine. The following code
snippet shows the content of the cookie file for the www.google.com
website:
User ID
2e88c198291a0dea7421210
www.google.com/
In the preceding code snippet, you can notice a single name-value pair,
which specifies the value of the User ID (2e88c198291a0dea7421210)
when the user has visited the www.google.com website.
NOTE:
It is possible that several other values may get stored in the file after the
name and value pair in the cookie file. These are housekeeping
Sikkim Manipal University
B2016
Page No. 12
Unit 1
information for the web browser. For example, the yahoo.com website
stores a bit more information on clients machine. When you open the
cookie file that yahoo has created on the machine, the following text is
available:
session-id-time
9067880093 yahoo.com
session-9067880093vctr3timeslog.yahoo.com/ x-main
6.
7.
8.
B2016
Page No. 13
Unit 1
What is HTTP?
a. Second-level domain name
b. Protocol
c. File name
d. Top-level domain name
Activity 2:
Make a list of the desirable features of your dream web browser.
Objective of the activity: To enhance your understanding of the features
of web browsers
This activity should not take you more than 10 minutes to complete.
1.4
B2016
Page No. 14
Unit 1
B2016
Page No. 15
Unit 1
1.5
Java Servlet and JSPs are the two frequently used Java based web
technologies that allow you to develop web applications. Both Java Servlet
and JSPs use Java Database Connectivity (JDBC) for handling database
operations in web applications.
In this section, we briefly introduce the following Java based web
technologies:
Java Servlet
JSP
1.5.1
Java Servlet
B2016
Page No. 16
Unit 1
B2016
Page No. 17
Unit 1
Servlets possesses a better performance than the CGI scripts for two
reasons. First is that once a Servlet is loaded into memory, it may be
called any number of times without the need of extra hardware as the
Servlet can run on a single lightweight thread. Another reason is that a
Servlet maintains a pool of connections to databases or other necessary
Java objects. This saves time required for processing requests.
B2016
Page No. 18
Unit 1
Servlets are accessible with wide range of service APIs available under
the Java platform; which allows us to solve complex problems by using a
simple API.
Next, lets understand the concept of JSPs, used for creating web
applications in Java.
1.5.2
JSPs
JSPs are files that contain HTML and Java code. JSPs have overcome the
shortcomings of Java Servlets. We learnt that Java Servlet is used to
develop server side extensions for presenting dynamic content to clients.
However, while using Java Servlet technology for creating dynamic views,
we can observe the numerous usage of the out.println statements.
System.out.println statement is used to print the arguments passed to it or
display the output. These output statements make the Java Servlet code
very complex and difficult to understand. Most of the code lines in a Servlet
contain static content presentation statements (in the out.println statements)
and contain very less Java logic, which leads to the following issues:
B2016
Page No. 19
Unit 1
B2016
Page No. 20
Unit 1
B2016
Page No. 21
Unit 1
used to retrieve client information. The response object can be used by the
Servlet to generate the response. The Servlet then invokes the
_jspService() method on the Servlet object and passes the created request
and response objects to the _jspService() method.
Destroying: This phase allows the Servlet container to destroy the JSP
pages Servlet instance or end the services provided by the Servlet
instance. In this phase, the Servlet container:
Allows all the threads currently in the service method of the Servlet
instance to complete their jobs and makes this instance unavailable for
new requests
Calls the destroy() method on the Servlet instance after the current
threads have completed their jobs
Till now we have discussed the various technologies used for creating web
applications. Next, we will discuss the architecture of web applications.
Self Assessment Questions:
13. Which of the following is an external application responsible to
process client requests and generate dynamic content?
a. API
b. CGI
c. Web server
d. JSP
14. Which of the following is an alternate to CGI?
a. API
b. Java servlet
c. JSP
e. Web server
15. Which of the following are advantages of a Java servlet?
B2016
Page No. 22
Unit 1
1.6
B2016
Page No. 23
Unit 1
Model-1 Architecture
The Model-1 architecture was the first development model used to develop
web applications. This model uses JSPs to design applications, which is
responsible for all the activities and functionalities provided by the
application. Applications using the Model-1 architecture contain a number of
JSP pages, with each page providing different functionalities and views to
different users.
Fig. 1.8 shows the Model-1 architecture:
B2016
Page No. 24
Unit 1
It involves the developer at both the page development and the business
logic implementation stages. Moreover, there is no scope for the splitting
of work between the web page designer and the business logic
developer.
Model-2 Architecture
B2016
Page No. 25
Unit 1
In the Model-2 architecture, the JSP and Java Servlet technologies were
used together to develop a web application. Servlets handle the control flow
while JSPs handle HTML page creation. In due course, the approach of
using JSPs and Servlets together evolved as the Model-2 architecture. In
this type of design model, the presentation logic is separated from the
business logic.
So far, Model-2 is the most successful development model used to develop
web applications. It not only overcomes the limitations of the Model-1
architecture, but also provides new features that have their own
advantages. Some of these advantages are as follows:
B2016
Page No. 26
Unit 1
19. How many types of development models are used for web
applications in Java?
a. One
b. Two
c. Three
d. Four
20. Which of the following statements are correct about the Model 1
architecture?
a. It uses JSP to design applications
b. It develops web applications by mixing the business and
presentation logic
c. It develops web applications by separating the business and
presentation logic
d. It is only suitable for small web applications
21. Which of the following is not a shortcoming of the Model-1
architecture?
a. It leads to inflexibility and difficulty in maintaining applications
b. It is suitable for large web applications
c. It is difficult to trace the flow of control and debug the program
22. Which of the following is not a feature of the Model-2 architecture?
a. It uses the JSP and Java servlet technologies together
b. It uses reusable software components to design business logic
c. It offers great flexibility to the presentation logic
d. It allows each software component to perform similar task
Activity 5:
Make a comparative list of the advantages and disadvantages of the two
models of web architecture.
B2016
Page No. 27
Unit 1
1.7
The MVC architecture allows separation of the business logic, data, and the
presentation logic. A web application can ensure a coherent interaction with
users by allowing the three components of MVC--Model, View, and
Controller--to communicate with each other. An application usually provides
different sets of information to its users. The content of a web application is
presented to users on different web pages in different formats. Different
users may require multiple types of interfaces, such as HyperTextMarkup
Language (HTML) for web customer, a Wireless Markup Language (WML)
for wireless customers, Java for administrators and XML-based web service
for suppliers. Therefore, in an application, we may need to create multiple
views for a single model.
When developing a small application, it sounds logical to interweave data
access, business logic, presentation logic, and control logic together.
However, for a large enterprise-level application, interweaving makes code
files more complex and it becomes difficult to manage files while
implementing changes in future. This causes the duplication of data access
and business logic code in the application at various points. As a result, the
implementation, testing, and maintenance efforts are also duplicated.
However, duplication can be reduced to save time and resources by
separating presentation logic, business logic, and control logic as different
components, which can easily be reused. This can be accomplished with
the Model-View-Controller (MVC) design pattern, which separates data
access, business logic, and presentation logic. The MVC model also
enables the creation of a number of views accessing the same enterpriselevel application model.
B2016
Page No. 28
Unit 1
Fig. 1.10 shows the interaction among the various MVC components:
The figure shows that View retrieves the data of an application by using the
query methods of the Model. Whenever a user sends a request, it passes
through the Controller. The Controller intercepts the request from the View
and passes it to the Model for appropriate action. In addition, the Controller,
which is a Servlet, stores all the business logic. A View, normally a JSP
page, contains all the code for presentation. A Model is implemented by
using a pure Java or bean class. The different components in the
application, such as Controller, Model, and View, are reusable and make
applications highly scalable. Lets closely examine each component of the
MVC architecture.
1.7.1
Model
B2016
Page No. 29
Unit 1
View
The View provides the Graphical User Interface (GUI) for Model. A user
interacts with the application through the View, which displays the
information based on the Model and allows the user to alter data. The Model
can have multiple Views. The information provided by the Model has
different meanings for different users and is interpreted by them in different
ways. The View is responsible for displaying the information to users in a
form that is understandable to them.
The Model manages the database, the content of which can be changed
and updated frequently. Any change in the database must be reflected to
the user as soon as possible. Therefore, the View communicates with the
Model to get information, if any change takes place in the database. Users
who want to modify the content of Model do not communicate with it directly.
Instead, they communicate with the Model through View, which
communicates with the Controller regarding the user input. The Controller
then makes the required changes in the Model and also notifies the other
associated Views.
Lets now examine the Controller component of MVC architecture.
1.7.3
Controller
The Controller controls all the Views associated with a Model. When a user
interacts with View and tries to update the Model, the Controller invokes
various methods to update the Model. The Controller of an application also
controls the data flow and transfers the requests between Model and View.
The behaviour of a web application is determined by the behaviour of its
various MVC components. The interaction among the various components
is managed by the Controller, which, by controlling the flow among these
components, determines the way the application performs the intended
tasks.
Sikkim Manipal University
B2016
Page No. 30
Unit 1
Lets understand how the Controller performs its role when a user needs to
change the data stored in a Model. If the user wishes to change this data,
the user sends a request to the Controller, which consults the Model to
update all the Views. The following steps are followed to change the data:
1.
2.
3.
4.
5.
6.
The View remains idle after the current interaction and waits for the
next interaction to begin.
B2016
Page No. 31
Unit 1
B2016
Page No. 32
Unit 1
29. In the MVC architecture, what provides the Graphical User Interface
(GUI) for Model?
a. Model
b. View
c. Client
d. Controller
30. To which component of the MVC architecture does the user send a
request if he/she wishes to change data?
a. Model
b. View
c. Client
d. Controller
Activity 6:
Choose any web application, examine its web architecture and write a
note on it.
Objective of the activity: To enhance your understanding of web
architecture models
This activity should not take you more than 15 minutes to complete.
1.8
Summary
All the public web sites connected to the Internet worldwide are referred
to as the World Wide Web. It is a system of connected
hypertext documents that can be retrieved using the Internet.
B2016
Page No. 33
Unit 1
URL stands for Uniform Resource Locator, which defines the unique
Internet address of a file stored on a host computer connected to the
Internet.
HTTP is the main protocol used for transmitting data on the web. It
defines how the computers on the web or Internet, specifically the server
and client, exchange data.
Java Servlet and JSPs) are the two frequently used Java based web
technologies that allow you to develop web applications. Both Java
Servlet and JSP use Java Database Connectivity (JDBC) for handling
database operations in web applications.
1.9
Glossary
B2016
Page No. 34
Unit 1
2.
Examine the evolution of the URL and the Domain Name System. How
have they improved the access to Internet?
3.
B2016
Page No. 35
Unit 1
4.
5.
6.
7.
Explain the JSP lifecycle. Underscore its role in handling and destroying
user requests.
8.
9.
1.11 Answers
Self Assessment Questions
1.
c.
2.
c.
1989
3.
d.
CERN
4.
a.
5.
b.
Lynx
6.
c.
Address bar
7.
a.
8.
a.
9.
b.
Protocol
10. c.
Byte code
11. b.
12. d.
13. b.
CGI
14. b.
Java servlet
B2016
Page No. 36
15. a.
Unit 1
b.
c.
16. a.
b.
c.
17. c.
Destroying
18. a.
b.
c.
19. b.
Two
20. a.
b.
c.
21. b.
22. d.
23. b.
24. c.
Client
25. d.
Controller
26. b.
View
27. a.
Model
28. a.
Model
B2016
Page No. 37
29. b.
View
30. d.
Controller
Unit 1
Terminal Questions
1.
Refer to section 1.2 Overview of World Wide Web, which deals with the
evolution of the World Wide Web.
2.
3.
4.
5.
6.
7.
8.
Refer to section 1.6 Web Architecture Models, which deals with Model1 and Model-2 architectures.
9.
Refer to section 1.7 The MVC Architecture, which deals with the MVC
architecture.
E-References
http://www.oracle.com/technetwork/articles/javase/webapps-1138794.html
http://www.vogella.com/articles/JavaWebTerminology/article.html
http://www.w3.org/
B2016
Page No. 38