0% found this document useful (0 votes)
18 views18 pages

b2 ch-1 Web

Uploaded by

ag298744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views18 pages

b2 ch-1 Web

Uploaded by

ag298744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Sumaya academy

8826767298,8826764330

Difference between Server Side


Scripting and Client Side Scripting
1. Client-side scripting :
Web browsers execute client-side scripting. It is used when browsers have
all code. Source code is used to transfer from webserver to user’s computer
over the internet and run directly on browsers. It is also used for validations
and functionality for user events.
It allows for more interactivity. It usually performs several actions without
going to the user. It cannot be basically used to connect to databases on a
web server. These scripts cannot access the file system that resides in the
web browser. Pages are altered on basis of the user’s choice. It can also be
used to create “cookies” that store data on the user’s computer.
2. Server-side scripting :
Web servers are used to execute server-side scripting. They are basically
used to create dynamic pages. It can also access the file system residing at
the webserver. A server-side environment that runs on a scripting language
is a web server.
Scripts can be written in any of a number of server-side scripting languages
available. It is used to retrieve and generate content for dynamic pages. It is
used to require to download plugins. In this load times are generally faster
than client-side scripting. When you need to store and retrieve information a
database will be used to contain data. It can use huge resources of the
server. It reduces client-side computation overhead. The server sends pages
to the request of the user/client.
Sumaya academy
8826767298,8826764330

What is N-Tier Architecture? How It


Works, Examples

N-tier architecture is also called multi-tier architecture because the


software is engineered to have the processing, data management, and
presentation functions physically and logically separated. That means
that these different functions are hosted on several machines or
clusters, ensuring that services are provided without resources being
shared and, as such, these services are delivered at top capacity. The
“N” in the name n-tier architecture refers to any number from 1.
Not only does your software gain from being able to get services at
the best possible rate, but it’s also easier to manage. This is because
when you work on one section, the changes you make will not affect
the other functions. And if there is a problem, you can easily pinpoint
where it originates.
Sumaya academy
8826767298,8826764330

A More In-Depth Look at N-Tier Architecture


N-tier architecture would involve dividing an application into three
different tiers. These would be the

1. logic tier,
2. the presentation tier, and
3. the data tier.
Sumaya academy
8826767298,8826764330

Image via Wikimedia Commons


The separate physical location of these tiers is what differentiates n-
tier architecture from the model-view-controller framework that only
separates presentation, logic, and data tiers in concept. N-tier
architecture also differs from MVC framework in that the former has
a middle layer or a logic tier, which facilitates all communications
between the different tiers. When you use the MVC framework, the
interaction that happens is triangular; instead of going through the
logic tier, it is the control layer that accesses the model and view
layers, while the model layer accesses the view layer. Additionally,
the control layer makes a model using the requirements and then
pushes that model into the view layer.
This is not to say that you can only use either the MVC framework or
the n-tier architecture. There are a lot of software that brings together
these two frameworks. For instance, you can use the n-tier
architecture as the overall architecture, or use the MVC framework in
the presentation tier.

What are the Benefits of N-Tier Architecture?


There are several benefits to using n-tier architecture for your
software. These are scalability, ease of management, flexibility, and
security.

 Secure: You can secure each of the three tiers separately


using different methods.
 Easy to manage: You can manage each tier separately,
adding or modifying each tier without affecting the other
tiers.
 Scalable: If you need to add more resources, you can do it
per tier, without affecting the other tiers.
 Flexible: Apart from isolated scalability, you can
also expand each tier in any manner that your requirements
dictate.

In short, with n-tier architecture, you can adopt new technologies and
add more components without having to rewrite the entire application
Sumaya academy
8826767298,8826764330

or redesigning your whole software, thus making it easier to scale or


maintain. Meanwhile, in terms of security, you can store sensitive or
confidential information in the logic tier, keeping it away from the
presentation tier, thus making it more secure.
Other benefits include:

 More efficient development. N-tier architecture is very


friendly for development, as different teams may work on
each tier. This way, you can be sure the design and
presentation professionals work on the presentation tier and
the database experts work on the data tier.
 Easy to add new features. If you want to introduce a new
feature, you can add it to the appropriate tier without
affecting the other tiers.
 Easy to reuse. Because the application is divided into
independent tiers, you can easily reuse each tier for other
software projects. For instance, if you want to use the same
program, but for a different data set, you can just replicate
the logic and presentation tiers and then create a new data
tier.

How It Works and Examples of N-Tier Architecture


When it comes to n-tier architecture, a three-tier architecture is fairly
common. In this setup, you have the presentation or GUI tier, the
data layer, and the application logic tier.
The application logic tier. The application logic tier is where all the
“thinking” happens, and it knows what is allowed by your application
and what is possible, and it makes other decisions. This logic tier is
also the one that writes and reads data into the data tier.
The data tier. The data tier is where all the data used in your
application are stored. You can securely store data on this tier, do
transaction, and even search through volumes and volumes of data in
a matter of seconds.
Sumaya academy
8826767298,8826764330

The presentation tier. The presentation tier is the user


interface. This is what the software user sees and interacts with. This
is where they enter the needed information. This tier also acts as a
go-between for the data tier and the user, passing on the user’s
different actions to the logic tier.
Just imagine surfing on your favorite website. The presentation tier is
the Web application that you see. It is shown on a Web browser you
access from your computer, and it has the CSS, JavaScript, and
HTML codes that allow you to make sense of the Web application. If
you need to log in, the presentation tier will show you boxes for
username, password, and the submit button. After filling out and then
submitting the form, all that will be passed on to the logic tier. The
logic tier will have the JSP, Java Servlets, Ruby, PHP and other
programs. The logic tier would be run on a Web server. And in this
example, the data tier would be some sort of database, such as a
MySQL, NoSQL, or PostgreSQL database. All of these are run on a
separate database server. Rich Internet applications and mobile apps
also follow the same three-tier architecture.
And there are n-tier architecture models that have more than three
tiers. Examples are applications that have these tiers:

 Services – such as print, directory, or database services


 Business domain – the tier that would host Java, DCOM,
CORBA, and other application server object.
 Presentation tier
 Client tier – or the thin clients

One good instance is when you have an enterprise service-oriented


architecture. The enterprise service bus or ESB would be there as a
separate tier to facilitate the communication of the basic service tier
and the business domain tier.

MVC Framework Introduction


The Model-View-Controller (MVC) framework is an architectural/design
pattern that separates an application into three main logical
Sumaya academy
8826767298,8826764330

components Model, View, and Controller. Each architectural component is


built to handle specific development aspects of an application. It isolates the
business logic and presentation layer from each other. It was traditionally
used for desktop graphical user interfaces (GUIs). Nowadays, MVC is one
of the most frequently used industry-standard web development frameworks
to create scalable and extensible projects. It is also used for designing
mobile apps.
MVC was created by Trygve Reenskaug. The main goal of this design
pattern was to solve the problem of users controlling a large and complex
data set by splitting a large application into specific sections that all have
their own purpose.
Features of MVC :

 It provides a clear separation of business logic, Ul logic, and input


logic.
 It offers full control over your HTML and URLs which makes it easy to
design web application architecture.
 It is a powerful URL-mapping component using which we can build
applications that have comprehensible and searchable URLs.
 It supports Test Driven Development (TDD).
Components of MVC :
The MVC framework includes the following 3 components:
 Controller
 Model
 View
Sumaya academy
8826767298,8826764330

MVC Architecture Design

Controller:
The controller is the component that enables the interconnection between
the views and the model so it acts as an intermediary. The controller doesn’t
have to worry about handling data logic, it just tells the model what to do. It
process all the business logic and incoming requests, manipulate data using
the Model component and interact with the View to render the final output.
View:
The View component is used for all the UI logic of the application. It
generates a user interface for the user. Views are created by the data which
is collected by the model component but these data aren’t taken directly but
through the controller. It only interacts with the compiler.
Model:
The Model component corresponds to all the data-related logic that the user
works with. This can represent either the data that is being transferred
between the View and Controller components or any other business logic-
related data. It can add or retrieve data from the database. It responds to the
controller’s request because the controller can’t interact with the database by
itself. The model interacts with the database and gives the required data
back to the controller.
Let’s understand the working of the MVC framework with an example:
Let’s imagine an end-user sends a request to a server to get a list of
students studying in a class. The server would then send that request to that
particular controller that handles students. That controller would then request
the model that handles students to return a list of all students studying in a
class.
Sumaya academy
8826767298,8826764330

The flow of Data in MVC Components

The model would query the database for the list of all students and then
return that list back to the controller. If the response back from the model
was successful, then the controller would ask the view associated with
students to return a presentation of the list of students. This view would take
the list of students from the controller and render the list into HTML that can
be used by the browser.
The controller would then take that presentation and returns it back to the
user. Thus ending the request. If earlier the model returned an error, the
controller would handle that error by asking the view that handles errors to
render a presentation for that particular error. That error presentation would
then be returned to the user instead of the student list presentation.
As we can see from the above example, the model handles all of the data.
The view handles all of the presentations and the controller just tells the
model and view of what to do. This is the basic architecture and working of
the MVC framework.
Advantages of MVC:
 Codes are easy to maintain and they can be extended easily.
 The MVC model component can be tested separately.
 The components of MVC can be developed simultaneously.
 It reduces complexity by dividing an application into three units. Model,
view, and controller.
 It supports Test Driven Development (TDD).
Sumaya academy
8826767298,8826764330

 It works well for Web apps that are supported by large teams of web
designers and developers.
 This architecture helps to test components independently as all classes
and objects are independent of each other
 Search Engine Optimization (SEO) Friendly.
Disadvantages of MVC:
 It is difficult to read, change, test, and reuse this model
 It is not suitable for building small applications.
 The inefficiency of data access in view.
 The framework navigation can be complex as it introduces new layers of
abstraction which requires users to adapt to the decomposition criteria of
MVC.
 Increased complexity and Inefficiency of data
Popular MVC Frameworks:
Some of the most popular and extensively used MVC frameworks are listed
below.
 Ruby on Rails
 Django
 CherryPy
 Spring MVC
 Catalyst
 Rails
 Zend Framework
 Fuel PHP
 Laravel
 Symphony
MVC is generally used on applications that run on a single graphical
workstation. The division of logical components enables readability and
modularity as well it makes more comfortable for the testing part.
TOOLS FOR SERVER SIDE SCRIPTING
Sumaya academy
8826767298,8826764330

HTTP PRIMITIVES
Sumaya academy
8826767298,8826764330

HTTP - Methods
The set of common methods for HTTP/1.1 is defined below and this set can be
expanded based on requirements. These method names are case sensitive and they
must be used in uppercase.

S.N. Method and Description

1 GET
Sumaya academy
8826767298,8826764330

The GET method is used to retrieve information from the


given server using a given URI. Requests using GET
should only retrieve data and should have no other effect
on the data.

2 HEAD

Same as GET, but transfers the status line and header


section only.

3 POST

A POST request is used to send data to the server, for


example, customer information, file upload, etc. using
HTML forms.

4 PUT

Replaces all current representations of the target


resource with the uploaded content.

5 DELETE

Removes all current representations of the target


resource given by a URI.

6 CONNECT

Establishes a tunnel to the server identified by a given


URI.

7 OPTIONS

Describes the communication options for the target


resource.

8 TRACE

Performs a message loop-back test along the path to the


target resource.
Sumaya academy
8826767298,8826764330

GET Method
A GET request retrieves data from a web server by specifying parameters in the
URL portion of the request. This is the main method used for document retrieval.
The following example makes use of GET method to fetch hello.htm:
GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
The server response against the above GET request will be as follows:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>

HEAD Method
The HEAD method is functionally similar to GET, except that the server replies with
a response line and headers, but no entity-body. The following example makes use
of HEAD method to fetch header information about hello.htm:
HEAD /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
The server response against the above HEAD request will be as follows:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Sumaya academy
8826767298,8826764330

Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
You can notice that here server the does not send any data after header.

POST Method
The POST method is used when you want to send some data to the server, for
example, file update, form data, etc. The following example makes use of POST
method to send a form data to the server, which will be processed by a process.cgi
and finally a response will be returned:
POST /cgi-bin/process.cgi HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Content-Type: text/xml; charset=utf-8
Content-Length: 88
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://clearforest.com/">string</string>

The server side script process.cgi processes the passed data and sends the
following response:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Request Processed Successfully</h1>
</body>
</html>

PUT Method
The PUT method is used to request the server to store the included entity-body at a
location specified by the given URL. The following example requests the server to
save the given entity-body in hello.htm at the root of the server:
PUT /hello.htm HTTP/1.1
Sumaya academy
8826767298,8826764330

User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)


Host: www.tutorialspoint.com
Accept-Language: en-us
Connection: Keep-Alive
Content-type: text/html
Content-Length: 182
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>

The server will store the given entity-body in hello.htm file and will send the
following response back to the client:
HTTP/1.1 201 Created
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>The file was created.</h1>
</body>
</html>

DELETE Method
The DELETE method is used to request the server to delete a file at a location
specified by the given URL. The following example requests the server to delete the
given file hello.htm at the root of the server:
DELETE /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Connection: Keep-Alive
The server will delete the mentioned file hello.htm and will send the following
response back to the client:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>URL deleted.</h1>
</body>
Sumaya academy
8826767298,8826764330

</html>

CONNECT Method
The CONNECT method is used by the client to establish a network connection to a
web server over HTTP. The following example requests a connection with a web
server running on the host tutorialspoint.com:
CONNECT www.tutorialspoint.com HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The connection is established with the server and the following response is sent
back to the client:
HTTP/1.1 200 Connection established
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)

OPTIONS Method
The OPTIONS method is used by the client to find out the HTTP methods and other
options supported by a web server. The client can specify a URL for the OPTIONS
method, or an asterisk (*) to refer to the entire server. The following example
requests a list of methods supported by a web server running on tutorialspoint.com:
OPTIONS * HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The server will send an information based on the current configuration of the server,
for example:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Type: httpd/unix-directory

TRACE Method
The TRACE method is used to echo the contents of an HTTP Request back to the
requester which can be used for debugging purpose at the time of development.
The following example shows the usage of TRACE method:
TRACE / HTTP/1.1
Host: www.tutorialspoint.com
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The server will send the following message in response to the above request:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Connection: close
Sumaya academy
8826767298,8826764330

Content-Type: message/http
Content-Length: 39

TRACE / HTTP/1.1
Host: www.tutorialspoint.com
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)

What is a web container?


A web container is the component of a web server that interacts with
Java servlets. A web container manages the life cycle of servlets; it maps a
URL to a particular servlet while ensuring that the requester has relevant
access-rights.

The web container implements the web component aspect of the Java
engineering architecture; it specifies a run time environment for various
components such as security, concurrency, transaction, and deployment.

Java servlets do not have a defined main() method, so a container is


required to load them. The servlet gets deployed on the container.

Let’s have a look at what happens when a client sends a certain request that
requires interaction with the servlet:

 The client sends a request to a web server.

 The web server, which contains a servlet, sends that request to the
container.

 The container passes the request to the respective servlet.

 The servlet methods are loaded.

 The servlet hands over the relevant response to the container, which
passes it to the server. Eventually, the response reaches the client.

You might also like