Vous êtes sur la page 1sur 24

Instituto Politcnico Nacional

Escuela Superior de Cmputo

THEMATIC UNIT I:
Introduction to Web Applications

M. en C. Hermes Francisco Montes Casiano


hermes.escom@gmail.com

Application Servers

ndice

1 Application Servers

Introduction
Java EE Application
Tomcat and Application Servers
Tomcat and Web Servers
A Brief History of Web Applications

2/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Introduction

As a Servlet container, Tomcat is a key component of a larger


set of standards collectively referred to as the Java Enterprise
Edition (Java EE) platform.
The Java EE standard defines a group of Java-based APIs that
are suited to creating Web applications for enterprises.

API
The term API (or application programming interface) is used by
software developers in general to describe services made available
to applica- tions by an underlying service provider

3/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Java EE Application Servers


As mentioned, an API simply defines services that a service
provider makes available to applications.
Various third parties provide commercial-grade
implementations of the Java EE APIs.
These implementations are typically packaged as a Java EE
application server.

Tomcat, Servlet container


Provides an implementation of the Servlet and JSP APIs,
application servers provide a superset of Tomcats functionality: the
Servlet and JSP APIs plus all the other Java EE APIs, and some
Java SE APIs (such as JNDI).
4/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Java EE Application Servers

4/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Tomcat and Application Servers


Tomcat has been referred to as an implementation of the
Servlet/JSP APIs (i.e., a Servlet container).

Tomcat is more than a Servlet container


It also provides an implementation of the JNDI and JMX APIs.
However, Tomcat is not a complete Java EE application server; it
doesnt provide support for even a majority of the Java EE APIs.
Many application servers actually use Tomcat as their
implementation of the Servlet and JSP APIs.

5/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Tomcat and Web Servers


Tomcats purpose is to provide standards-compliant support
for Servlets and JSPs.
The purpose of Servlets and JSPs is to generate Web content
such as HTML files or GIF files on demand, using changing
data.
Web content that is generated on demand is said to be
dynamic.
Web content that never changes and is served up as is, is
called static.

Web Applications
Web applications commonly include a great deal of static content,
such as images or Cascading Style Sheets (CSS).
6/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Tomcat and Web Servers


While Tomcat is capable of serving dynamic and static content,
many production deployments use a native Web server, such
as Apache HTTP Server or IIS, to handle the static content.

Tomcat included a Connector that enabled a Tomcat and


Apache Web server to work together.
6/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

History of Web Applications

Initial Web sites were static they merely served up HTML


pages.
The protocol for serving up Web pages, Hypertext Transfer
Protocol (HTTP), was a simple, stateless protocol.
The following technologiesare used for building dynamic Web
sites:
1
2
3
4

CGI scripts
Server-based Java technologies: servlets, JSPs, and tag libraries
MVC architecture, and implementations (Struts, for example)
Web applications built using the preceding technologies

7/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

CGI Scripts
Was the first mechanism for serving up dynamic content to
users.
Executable applications were provided with an interface that
enabled clients to access them in a standard way over HTTP.
CGI suffered from several drawbacks:
1

2
3

Each incoming CGI request required starting an operating


system process.
This process would then load and run a (CGI) program.
Tedious and repetitive coding was needed to handle the
network protocol and request decoding.

Performance problem
The first two operations in the previous list can use a large number
of CPU cycles and a lot of memory.
8/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: Servlets


Servlets are portions of logic written in Java that have a
defined form and are invoked to dynamically generate content
or perform some action.

Servlets overcome the problems mentioned earlier with CGI


programs
1

The overhead of starting an operating system process for each


request is eliminated.

Java classes are loaded by the JVM to process incoming requests.

The issue of managing state over a stateless protocol such as HTTP


is solved.

Code that handles the networking protocol and decodes incoming


requests can be shared by all the request-processing Java classes.
9/15

THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: Servlets

Figura : Servlet methods


9/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: Servlets

Figura : Servlet containers


9/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: JSP


The first edition of the JavaServer Pages (JSP) specifications
resembled Active Server Pages (ASP), a Microsoft technology.
Both have since evolved from those early days so much that
the resemblance is now purely superficial.
JSP has made a huge leap forward with the introduction of
tag libraries.

Tag Libraries
These tag libraries are collections of custom tags, and each tag
corresponds to a reusable Java module.
The JSP is compiled into a servlet class the first time it is
invoked.
10/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: JSP


This servlet is then called for each subsequent request,
avoiding the parsing and compiling of the JSP every time a
user accesses the site.
Like servlets, JSPs operate within a container.
The JSP container provides the same services as a Servlet
container.
JSP container requires the additional steps of conversion to
servlet code and compilation before the JSP is executed.

Apache Tomcat
Includes both the Servlet container named Catalina that executes
servlets and com- piled JSPs, and the compiler for JSP files (the
Jasper compiler).
10/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Server-based Java technologies: JSP


This servlet is then called for each subsequent request,
avoiding the parsing and compiling of the JSP every time a
user accesses the site.
Like servlets, JSPs operate within a container.
The JSP container provides the same services as a Servlet
container.
JSP container requires the additional steps of conversion to
servlet code and compilation before the JSP is executed.

Web container
The combination of a JSP compiler and a Servlet container is
known as a Web container
10/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture: Model 1


Architecture

11/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture: Model 1


Architecture

Even with the use of servlets and JSPs, a lot of


unmaintainable Web applications were built in the early days
of Web development.
There were two major causes of this:
1
2

The control flow of the Web application.


The business logic of the Web site was tightly coupled with the
user interface presentation.

This architecture is suitable only for small sites with limited


functionality, or Web pages with minimal requirements for
expansion.

11/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture: Model 2


Architecture and Web Frameworks

Do not embed the logic of handling user requests and the


control flow inside the JSP pages themselves.
Do not mix the application logic with the user interface logic.
Keep Java code (a.k.a. scriptlets) out of JSPs.
Another best practice is the use of JSPs as templates.

12/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture


JSP Tag Libraries

JSPs were an improvement over servlets, as far as a


mechanism of generating HTML content is concerned.
However, JSPs often had a lot of Java code embedded in
them.
This makes it hard for HTML designers, who often do not
have a background as Java developers.
Tag libraries help solve this issue to some extent.

JSP Expression Language


Defines an easy-to-use syntax for accessing Java beans,
request/session parameters, and HTTP headers from JSPs. Thus
doing away with the need for any Java scriptlet code inside a JSP.
13/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture


Model View Controler(MVC)

Aids in the separation of application logic and presentation of


HTML content

MVC
1

The Model is the logic of the site

The View component of this architecture is naturally the JSPs


that display the content that is created.

The Controller designates which part of the Model is invoked,


and which JSP is used to render the data.

14/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Web Application Architecture


Model View Controler(MVC)

MVC
1

The Model is the logic of the site

The View component of this architecture is naturally the JSPs


that display the content that is created.

The Controller designates which part of the Model is invoked,


and which JSP is used to render the data.
Chapter 2: Web Applications: Servlets, JSPs, and More
Client

Server

M
M

Forwards
request
Request

Returns result
Controller
Forwards result

Returns result
to client
Returns rendered
request result

Figure 2-7: Expanded MVC architecture

14/15
Small-scale, homegrown sites that are not based
on a framework are often a looser version of this architecture. Several servlets each take the role of a Controller and part of the Model. In this version of the
THEMATIC UNIT I: Introduction
to Web Applications
Hermes Francisco Montes Casiano
Model 2 architecture, the JSPs are still designed so that they contain very little or no logic and the serv-

Application Servers

Web Application Architecture


Model View Controler(MVC)

There are two typical types of this model architecture:


1 Strict:
Designates the role of the Controller to a single servlet, which
extracts the information needed to route the query to a piece
of logic
executes the logic component
And then forwards the result of the execution to a JSP.
2

Loose:
Several servlets each take the role of a Controller and part of
the Model.
The JSPs are still designed so that they contain very little or
no logic and the serv- lets handle all of the functions of the
application.

14/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Application Servers

Using Appropiate Web Technologies

Well-designed, modern-day Web applications use all of the


server-side Java technologies mentioned, but where they are
appropriate:
Servlets are used to implement application logic.
JSPs are used for presentation of content.
Tag libraries and JSP EL are used instead of embedding Java
code inside JSPs.
MVC frameworks such as Struts are used to aid in the
separation of presentation and application logic.

15/15
THEMATIC UNIT I: Introduction to Web Applications

Hermes Francisco Montes Casiano

Vous aimerez peut-être aussi