b2 ch-1 Web
b2 ch-1 Web
8826767298,8826764330
1. logic tier,
2. the presentation tier, and
3. the data tier.
Sumaya academy
8826767298,8826764330
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
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 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.
1 GET
Sumaya academy
8826767298,8826764330
2 HEAD
3 POST
4 PUT
5 DELETE
6 CONNECT
7 OPTIONS
8 TRACE
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
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)
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.
Let’s have a look at what happens when a client sends a certain request that
requires interaction with the servlet:
The web server, which contains a servlet, sends that request to the
container.
The servlet hands over the relevant response to the container, which
passes it to the server. Eventually, the response reaches the client.