On Java Development

All things related to Java development, from the perspective of a caveman.

Anatomy of a Web Application

without comments

Introduction

This post is for the reader who is curious about the architecture, components and technologies that make up a web application.

Technologies

This section presents an overview of the technologies used by a web application.

Java

Originally from Sun Microsystems and now owned by Oracle, Java is a set of software libraries providing the foundation for developing applications that are deployed on :

  • embedded devices (mp3 players, modems, phones, etc).
  • fat clients such as PC’s
  • a server container running in a Windows or Unix environment

 
The Web Application Container
A web container or Servlet container provides the means of mapping URLs to an assigned servlet that is written using Java. Servlets are a part of the front-end of an application that interacts with the browser and the rest of the application to which it belongs. Servlets receive HTTP requests and send HTTP responses to facilitate transactional conversations between the browser and a database. The database can be located on the same machine as the web container or, when implementing a multi-tiered architecture, on another machine located on the same network that usually sits behind a firewall. Examples of some web containers are listed below.

Non-Commercial Web Containers

Commercial Web Containers

 
Layers of a Java web application
This section presents the different layers that make up a typical Java web application that can be divided into 4 layers as shown by the diagram.

WebAppLayers

It should be apparent by the diagram that each layer is made up from a distinct set of source code that are responsible for different tasks. This means that the Application Layer will not contain logic that writes records to the database. Instead, it will call upon the services provided by the Domain (Persistence) Layer to perform those tasks. When coded in an object oriented manner, this means there is a large potential for other applications to reuse the classes defined within this layer.

 
Presentation Layer
This is the layer of the application that interacts with the user to send and receive information to and from the application layer. Java Server Faces (JSF) based technologies are used to build the web pages which when requested are translated into HTML before being sent to the browser.

Before JSF, there was only JavaServer Pages (JSP). JSP was first introduced in 1999. It used Java Beans to pass data between the servlet and the web page. In this development model, a servlet class name was associated to a url using mapping entries added to the application’s web.xml file. Each web page usually meant a new entry had to be made to that file. Read more about JavaServer Pages here.

JSP has been superseded by the JavaSever Faces (JSF) specification (JSF 1.1) which was issued on March 11, 2004. As a result, JSP has been deprecated. Today, JSF is widely considered as the new standard Java framework for building Web applications. Web applications constructed with JSF don’t use servlets and Java Beans have been replaced by the ManagedBean. Read more about JavaServer Faces here.

There are many technologies based on the JSF specification that can be used by the application to present information to the browser. Some are listed here.

 
Application / Service Layer
This layer sits between the presentation layer and the persistence layer and contains the bulk of the application’s processing responsibilities. It receives the data sent from the Presentation Layer, process it and if required persists the information to the database. It is also responsible for retrieving information from the database to send it back to the presentation layer. It is comprised of logic that uses services that contain the application’s business rules. This layer uses the logic contained within the persistence layer.

 
Domain / Persistence Layer
This layer represents the domain within which descriptions of the data entities (files) and the logic that performs create, read, update and delete (CRUD) operations on the database exists. These I/O related operations are also known as add, change, insert and delete (ACID). As a result of the data persistence related responsibilities, this layer is also called the Persistence Layer.

The logic in this layer interacts directly with the database using interfaces into software designed to persist data. One such example of this type of software is Hibernate. Hibernate allows data to be written without having to expose to the application the type of database being used. This means the application is database agnostic. This is a perfect choice for software vendors who cannot choose the database for their product as they do not know which database a future customer is using or for that matter, the machine it will be running on. This in itself is the biggest reason for choosing Java. Data Access Object (DAO) classes reside in this layer.

 
Infrastructure
The infrastructure provides the scaffolding for the Application and Persistence layer. This is represented by any Java libraries developed in-house as well as open-source solutions provided by the Apache Software Foundation, Spring and Hibernate to name a few. Spring offers messaging and web layer support as well as bean management. Hibernate provides support for data persistence and retrieval across relational database systems implemented by vendors such as IBM, Oracle, MS and others.

 
Visual of the Moving Parts

The diagram below illustrates the technologies used by a web application and their relationships.

WebAppAnatomy

 
Summary
This post introduced some of the major moving parts of a web application. For more information about servlets and some of the common activities that must take place when a web-application starts, see this post.

Leave a Reply

You must be logged in to post a comment.