THE MIDDLE TIER
The Java EE server sits on the Middle tier and provides two logical containers: the web container
and the EJB container. These containers roughly correspond to the Web layer and the Business layer,
respectively. Each layer has distinct but sometimes overlapping responsibilities.
The MVC pattern is commonly used to clearly separate the view generation responsibilities of the
Web layer from the data modeling responsibilities of the Business layer. Chapter 14, “Model Viewer
Controller Pattern,” discusses in detail how to implement this separation of concerns.
The Web layer manages the interactions between the Client tier and the Business layer.
The Web layer receives a request for a resource from the Client tier. The request may include data
that the user inputted, such as a username and password or sign‐up information. The request is
processed and, if necessary, an interaction between the Web layer and the Business layer takes place.
The response is dynamically prepared in one of several forms (usually in the form of a HyperText
Markup Language [HTML] web page for a response originating from a browser) and sent to the
The Web layer maintains the user's states in a session and may even perform some business logic and
temporarily persist data in memory.
The technologies that are typically used in the Web layer relate to the management of the
interactions between the Client tier and the Middle tier and the construction of the response.
Serlvets control the web l ow and manage interactions while JavaServer Pages (JSP), Expression
Language (EL), and JavaServer Pages Standard Tag Library (JSTL) prepare the response to the
client. This is just a snapshot of the technologies that you can use in the Web layer. For a complete
list, see Figure 2-2.
In Java EE 7, four new technologies were added to the EE universe: WebSockets, Concurrency
Utilities, Batch, and JSON‐P. You can use all but WebSockets in both layers.
The Business layer executes business logic that resolves business problems or satisi es a particular
business need within the business domain.
Normally, this would involve data that has been retrieved from the database in the EIS tier or
collected from the client. In a banking domain, a transaction fee might be applied to a transaction
amount and sent to the client via the Web layer for the client to coni rm the transaction. In an
e‐commerce domain, a different tax rate might be applied to a product depending on the physical
location of the client before being passed to the Web layer, and the web page would be rendered
according to this info.
The Business layer is where the core logic of the business application resides. Business logic is
wrapped up in the EJB, and the data used by the business logic is retrieved from the EIS tier via
Java Persistence API (JPA), Java Transaction API (JTA), and Java Database Connectivity (JDBC).