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

J2EE Multi-Tier Architecture Overview

J2EE, now known as Jakarta EE, is a standard for developing multi-tier, distributed enterprise applications, structured into four logical tiers: Client, Web, Business, and Enterprise Information System. The architecture enhances scalability, modularity, and security, with components like Servlets, JSPs, and EJBs managing different functionalities. Session management is crucial for tracking user interactions, utilizing techniques such as cookies and URL rewriting to maintain state across HTTP requests.

Uploaded by

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

J2EE Multi-Tier Architecture Overview

J2EE, now known as Jakarta EE, is a standard for developing multi-tier, distributed enterprise applications, structured into four logical tiers: Client, Web, Business, and Enterprise Information System. The architecture enhances scalability, modularity, and security, with components like Servlets, JSPs, and EJBs managing different functionalities. Session management is crucial for tracking user interactions, utilizing techniques such as cookies and URL rewriting to maintain state across HTTP requests.

Uploaded by

Ramya Duraisamy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

J2EE

The Java 2 Platform, Enterprise Edition (J2EE), now known as Jakarta EE, defines a
standard for developing multi-tier, distributed enterprise applications. This architecture
separates the application's functionality into distinct tiers, which can be deployed on different
machines to enhance scalability, modularity, and security.

J2EE applications are typically structured as a Four-Tier Architecture (which is an


extension of the common three-tier model):

J2EE Enterprise Tiers and Components


The J2EE platform breaks down the application into four logical tiers, with the middle tier
(Business Logic) often split into the Web Tier and the EJB/Business Tier.

1. Client Tier (Presentation)

This is the client-side layer where the end-user interacts with the application.

 Function: Handles user input and displays application output. It primarily


communicates with the Web Tier.
 Components:
o Web Clients: A standard web browser running static HTML pages and
dynamic content generated by the Web Tier (Servlets/JSPs). These are
typically thin clients.
o Application Clients: Standalone Java applications (like rich desktop
clients) that run on the client machine and can directly access the Business
Tier components.
o Applets: (Historically common) Small programs embedded in HTML pages,
running within a Java Plug-in.

2. Web Tier (Server-Side Presentation)

This is the first tier on the server side, primarily handling client requests and managing the
flow of data between the client and the business logic.

 Function: Processes HTTP requests, controls navigation, generates dynamic web


pages, and acts as a controller in the MVC pattern.
 Container: Web Container (e.g., in Tomcat, WebLogic, JBoss) manages the
execution of Servlets and JSPs.
 Components:
o Java Servlets: Java classes that dynamically process requests and construct
responses.
o JavaServer Pages (JSP): Text-based documents that contain static template
data and dynamic content logic (often used for the "View").
o JavaServer Faces (JSF): A component-based UI framework built on top of
the Servlet API.
3. Business Tier (EJB Tier / Middle Tier)

This layer contains the core logic that defines the application's purpose and functionality.
This logic is decoupled from both the client presentation and the data storage mechanisms.

 Function: Implements the Business Logic, handles complex transactions, enforces


business rules, and manages access to the Enterprise Information System (EIS) Tier.
 Container: EJB Container (part of the J2EE Application Server) manages the
lifecycle of Enterprise JavaBeans, providing services like security, transaction
management, and resource pooling.
 Components (Enterprise JavaBeans - EJBs):
o Session Beans: Implement business processes and logic. They can be Stateful
(for conversations with a specific client) or Stateless (for general, non-client-
specific tasks).
o Message-Driven Beans (MDBs): Used for asynchronous business logic
execution, typically listening for and processing messages from a Java
Message Service (JMS) queue or topic.

4. Enterprise Information System (EIS) Tier (Data Tier)

This is the back-end layer where enterprise data resides and persists.

 Function: Provides connectivity and storage for data sources. The Business Tier is
the only tier that directly interacts with this layer.
 Components:
o Databases: Relational (Oracle, MySQL, PostgreSQL) and NoSQL databases.
o Legacy Systems: Older systems and mainframes containing critical business
data.
o APIs/Technologies: Java Database Connectivity (JDBC) and Java
Connector Architecture (JCA) are used by the Business Tier components to
communicate with the resources in this tier.

J2EE Clients
In the J2EE (Java 2 Platform, Enterprise Edition) multi-tier architecture, the Client Tier
is the end-user interface through which users access and interact with the enterprise
application.

J2EE applications support several types of clients, which are generally categorized based on
whether they are thin (rely heavily on the server for processing) or thick/rich (perform more
processing locally).

1. Web Clients (Thin Clients)


These are the most common clients and represent the thin-client approach, relying on
standard web protocols.

 Description: A standard web browser running on the client machine. These clients
are generally the simplest to deploy and maintain.
 Interaction: They communicate with the Web Tier of the J2EE application using
HTTP/HTTPS and receive content generated by Servlets and JavaServer Pages
(JSPs).
 Technologies:
o HTML, CSS, JavaScript: Used for presentation and dynamic client-side
behavior.
o AJAX/Fetch: Used for asynchronous communication with the server to
update parts of the page without a full reload.

2. Application Clients (Thick/Rich Clients)

These are standalone Java applications that run on the client's machine. They are
considered thick because they contain presentation logic and often directly interact with the
Business Tier.

 Description: A custom-developed Java application that typically uses a graphical user


interface (GUI) framework.
 Interaction: They can communicate directly with the Business Tier using the
Remote Method Invocation over Internet Inter-Orb Protocol (RMI-IIOP) to call
methods on Enterprise JavaBeans (EJBs).
 Technologies:
o Swing or JavaFX: Used for developing rich GUIs.
o Java Naming and Directory Interface (JNDI): Used to look up and obtain
references to EJB components on the server.

3. Applets (Historical)

Applets were small Java programs downloaded from a web server and executed within a web
browser using the Java Plug-in.

 Description: They provided the benefit of a rich Java interface but were deployed
easily via the web.
 Current Status: Applets have been largely deprecated and are no longer commonly
used due to security concerns and the rise of modern web technologies like HTML5
and JavaScript frameworks.

🔗 Client Interaction in J2EE


The J2EE client typically performs the following steps:

1. Initiates a Request: The user interacts with the client interface (e.g., clicks a button).
2. Accesses the Web Tier: The Web Client sends an HTTP request to a Servlet or JSP
in the Web Tier.
3. Invokes Business Logic: The Servlet/JSP acts as a controller, often delegating the
core processing to a Session Bean in the Business Tier.
4. Receives Response: The Business Tier executes the logic, potentially interacts with
the Data Tier, and returns the result back to the Web Tier.
5. Presents Data: The Web Tier formats the result (e.g., as HTML) and sends it back to
the client browser for display.

Session Management in J2EE


In J2EE (Java 2 Platform, Enterprise Edition), Session Management is the process by
which a server keeps track of a specific user's interaction and state across multiple,
consecutive HTTP requests. Since HTTP is a stateless protocol (meaning each request is
independent), the server needs a mechanism to remember who the user is and what actions
they have taken during their visit to the application.

The HttpSession Object


The core mechanism for session management in the J2EE Web Tier is the HttpSession
object, which is managed by the Web Container (e.g., Tomcat, Jetty).

How It Works:

1. Creation: When a client (browser) makes its first request to a servlet or JSP, and the
server needs to store state for that user, the Web Container creates a new
HttpSession object.
2. Session ID: A unique identifier, the Session ID, is assigned to this new session.
3. Communication: The container then sends the Session ID back to the client, usually
embedded in a Cookie or rewritten into the URL.
4. Subsequent Requests: On all subsequent requests from the same client, the client
sends this Session ID back to the server.
5. State Retrieval: The container uses the received Session ID to locate the
corresponding HttpSession object and makes it available to the Servlets/JSPs
handling the request.
6. Data Storage: Developers use the HttpSession object to store and retrieve user-
specific data as key-value pairs (attributes) using methods like setAttribute() and
getAttribute().

Example: Storing a user's logged-in status or items added to a shopping cart.

🔑 Session Tracking Techniques


The Web Container uses various techniques to maintain the link between the client and the
HttpSession object:

1. Cookies (Most Common)

 The container sends the session ID back to the client in a special cookie, often named
JSESSIONID.
 The browser automatically includes this cookie in all subsequent requests to the
server, allowing the container to identify the session.
 Pros: Seamless, efficient, and standard practice.
 Cons: Requires the client browser to have cookies enabled.

2. URL Rewriting

 If cookies are disabled on the client, the container can append the session ID directly
to the URL of every link generated by the server.
 The format usually looks like: .../[Link];jsessionid=ABCD12345
 Pros: Works even when cookies are disabled.
 Cons: Clutters the URL, requires server-side code to rewrite all links, and can be
exposed if the user bookmarks a page with the session ID.

3. Hidden Form Fields

 In specific scenarios (e.g., submitting a sequence of forms), the session ID can be


stored in a hidden form field (<input type="hidden">).
 The ID is sent back to the server as a parameter when the form is submitted.
 Pros: No reliance on cookies or URL rewriting.
 Cons: Only works when a form is submitted, limiting its general use for navigation.

🛑 Session Lifecycle Management


A session does not last indefinitely. The container manages its lifecycle using the following
events and methods:

Action Description Method/Event

If the session remains inactive for a period defined


Timeout in the deployment descriptor ([Link]), the [Link] timeout setting
container automatically invalidates it.

The application code explicitly ends the session,


Invalidation usually when the user logs out. All session attributes [Link]()
are lost.
Action Description Method/Event

HttpSessionBindingListener can be
valueBound(),
Binding implemented by objects to be notified when they are valueUnbound()
added to or removed from the session.

The J2EE (Java 2 Platform, Enterprise Edition) multi-tier architecture is centrally defined by
its Web Tier (server-side presentation) and EJB Tier (business logic), with J2EE Web
Services providing a standardized way for them to communicate with external systems.

1. Web Tier vs. EJB Tier: Components & Technologies


The Web and EJB Tiers are the two primary server-side layers, each running within its own
specialized container that provides essential services (like security, transaction management,
and lifecycle management).

Feature Web Tier EJB Tier (Business Tier)

Handles client interaction,


Implements the core business logic, handles
controls application flow, and
Primary Role complex transactions, and manages data
generates dynamic web
access.
content.

J2EE Web Container (e.g., in EJB Container (part of the J2EE Application
Container Tomcat, Jetty) Server)

Servlets, JavaServer Pages Enterprise JavaBeans (EJBs): Session Beans


Key
(JSPs), Filters, Tag Libraries, (Stateless/Stateful), Message-Driven Beans
Components
Web Event Listeners. (MDBs).

Primarily accessed by the Web Tier


Accessed by Web Clients
components or Application Clients using
Client Access (browsers) using
RMI-IIOP (Remote Method Invocation over
HTTP/HTTPS.
Internet Inter-Orb Protocol).

Servlet API, JSP API, JSTL


Key EJB API, JTA (Java Transaction API), JMS
(JSP Standard Tag Library),
Technologies (Java Message Service) for MDBs.
JSF (JavaServer Faces).
2. J2EE Web Services
J2EE Web Services allow the application's functionality (typically defined in the EJB Tier)
to be exposed to external, often non-Java, systems over standard network protocols. This is a
key requirement for enterprise interoperability.

Technologies and Components:

 Endpoint Implementation: Web Services in J2EE are often implemented by


exposing a Stateless Session Bean or a Servlet.
 Protocols and Formats:
o SOAP (Simple Object Access Protocol): Used for exchanging structured,
XML-based information between applications.
o WSDL (Web Services Description Language): An XML format used to
describe the service's interface (what methods it offers, how to call them, and
where it is located).
o UDDI (Universal Description, Discovery, and Integration): A registry for
publishing and discovering web services (less common now).
 J2EE APIs for Web Services:
o JAX-RPC (Java API for XML-based RPC) / JAX-WS (Java API for XML
Web Services): APIs used to define and consume SOAP-based web services.
o SAAJ (SOAP with Attachments API for Java): Used for manipulating SOAP
messages and attachments.
o JAXB (Java Architecture for XML Binding): Used for mapping Java objects
to and from XML documents.

3. The .NET Framework in J2EE


The .NET Framework is Microsoft's platform for developing and running applications,
acting as a competitive counterpart to the J2EE/Java EE platform. It is not a component or
technology within the J2EE specification itself.

In a typical enterprise environment with both platforms, the relationship is one of


interoperability (the ability of systems built on different platforms to work together).

Interoperability Mechanisms:

 XML Web Services: This is the most common and standardized way to connect
J2EE and .NET applications.
o A J2EE EJB can be exposed as a Web Service, which a .NET client (using
C# or [Link]) can consume using its built-in SOAP support.
o Conversely, a .NET Web Service can be consumed by a J2EE component
(Servlet or EJB) using JAX-WS.
 Runtime Bridges (Third-Party Tools): Specialized third-party software (like
JNBridgePro) allows Java and .NET code to directly invoke methods on components
from the other platform, bridging the gap between the Java Virtual Machine (JVM)
and the Common Language Runtime (CLR).
 Messaging and Shared Databases: Asynchronous communication is achieved using
standard protocols like JMS (Java Message Service) on the J2EE side and MSMQ
(Microsoft Message Queue) or a shared relational database accessed via JDBC
(J2EE) and [Link] (.NET).

The J2EE (Java 2 Platform, Enterprise Edition) architecture is built upon a set of fundamental
design principles and the application of proven Design Patterns to address the complexities
inherent in building large-scale, distributed enterprise systems. The core goal is to achieve
applications that are scalable, reliable, maintainable, and secure.

Core Architectural Principles


The J2EE platform enforces several principles through its structure and APIs:

1. Multi-Tier Architecture and Separation of Concerns

This is the most critical principle. The application is logically and often physically separated
into distinct layers.

 Principle: Decoupling the various parts of the application (presentation, business


logic, data access) so that changes in one area have minimal impact on others.
 Implementation in J2EE: The Web Tier (Servlets/JSPs) handles the UI
(Presentation), the EJB Tier (Session Beans) handles the core business rules (Logic),
and the EIS Tier (Databases) handles data persistence.

2. Component-Based Development

J2EE applications are constructed from reusable, self-contained components.

 Principle: Use well-defined, modular components to encapsulate specific


functionality, promoting reuse and simplifying development.
 Implementation in J2EE: Servlets, JSPs, and Enterprise JavaBeans (EJBs) are
the primary component models, each with a specific role and lifecycle managed by its
container.

3. Container-Managed Services

The J2EE server environment (the Application Server) provides essential infrastructure
services, freeing developers to focus on business logic.

 Principle: Delegation of cross-cutting concerns (like security, transaction


management, and resource pooling) to the container.
 Implementation in J2EE: The Web Container and EJB Container automatically
handle:
o Transaction Management (JTA): Ensuring data integrity across multiple
operations.
o Security: Authentication and authorization checks.
o Lifecycle Management: Creating and destroying components (like EJBs) as
needed.
4. Loose Coupling and Abstraction

Components should minimize their direct dependency on each other, often communicating
through interfaces or standardized mechanisms.

 Principle: Reduces the complexity and makes the system more flexible and easier to
test.
 Implementation in J2EE: Use of Remote Interfaces for EJBs and APIs like JNDI
(Java Naming and Directory Interface) to look up resources and services, abstracting
the physical location.

📐 Key Design Patterns (Core J2EE Patterns)


J2EE design principles are often implemented using proven design patterns, which are
reusable solutions to common problems in enterprise development.

Presentation Tier Patterns

These patterns manage client requests and view generation:

 Model-View-Controller (MVC): Separates the application into three parts:


o Model: Business logic and data (often handled by the EJB Tier or POJOs).
o View: Presentation/UI (JSPs, HTML).
o Controller: Handles requests, calls the Model, and selects the View (Servlets,
Front Controller pattern).
 Front Controller: A single handler (Servlet) centralizes request processing and
controls workflow for the Web Tier, standardizing the application's entry point.

Business Tier Patterns

These patterns manage the business logic and client interaction with EJBs:

 Session Facade: Provides a unified, coarse-grained interface to the Business Tier.


It bundles related business logic calls into a single method on a Session Bean,
reducing network overhead (remote calls) and simplifying the client's view of the
system.
 Business Delegate: Reduces coupling between the Presentation Tier (Web) and the
Business Tier (EJB). It hides the complexity of looking up (via JNDI) and accessing
the EJB remote interfaces.

Integration Tier Patterns

These patterns handle communication with the data and legacy systems:

 Data Access Object (DAO): Abstract and encapsulate all access to the data source
(database). The business logic components use the DAO interface without knowing
the specific database technology (e.g., JDBC, Hibernate) being used, allowing the
underlying persistence mechanism to change easily.
 Transfer Object (or Data Transfer Object - DTO): An object used to transfer data
efficiently between tiers. Instead of making multiple remote calls to get individual
fields, a single DTO object containing all necessary data is passed, significantly
reducing network traffic.

Alternative Implementations Networking

Common questions

Powered by AI

The J2EE architecture separates application functionality into distinct tiers to enhance scalability, modularity, and security by logically separating concerns. This separation supports the architectural principle of Separation of Concerns by decoupling presentation, business logic, and data access layers, thus reducing dependencies and allowing each layer to evolve independently without impacting others. Scalability is achieved by distributing these tiers across different machines, enabling load balancing and optimizing resource allocation .

The EJB Container manages the lifecycle of Enterprise JavaBeans, providing essential services like security, transaction management, and resource pooling, which are crucial for addressing cross-cutting concerns. By handling these aspects, the container enables developers to focus on business logic rather than infrastructure concerns, thereby promoting modularity and reducing complexity. Security is enforced by authentication and authorization checks, while transaction management ensures data integrity across multiple operations .

J2EE APIs like JTA, JAX-RPC, and JNDI are crucial for building modular and flexible applications. JTA handles transaction management, ensuring atomicity and data consistency across distributed systems, while JAX-RPC (and its successor JAX-WS) facilitates creating platform-independent web services, enhancing interoperability. JNDI abstracts resource lookups, decoupling applications from resource locations, thereby improving modularity and flexibility by allowing resource configurations to change without affecting code .

The EIS Tier in J2EE serves as the back-end layer providing connectivity and persistence for enterprise data. It interacts primarily with the Business Tier, which accesses the data using technologies like JDBC and JCA. This tier handles communication with databases, legacy systems, and other data sources, ensuring data retrieval and manipulation are seamlessly integrated into business processes, thus maintaining the integrity and continuity of enterprise operations .

J2EE web services facilitate interoperability by enabling different technology stacks, like .NET, to communicate using standardized protocols such as SOAP and WSDL. A J2EE EJB can be exposed as a SOAP-based web service, which can be consumed by .NET clients, ensuring seamless interaction despite differing technology stacks. Similarly, J2EE components can consume web services from .NET, using JAX-WS to interact with them, thus breaking down silos and allowing systems to work together efficiently .

The MVC pattern enhances manageability by separating an application's concerns into three distinct components: Model (business logic), View (UI), and Controller (request handling). This separation allows developers to change one part, such as the UI, without affecting the underlying business logic, increasing flexibility. Scalability is achieved as each part can be distributed across different servers, thus optimizing resource use and ensuring performance efficiency under load .

Web Clients are thin clients that generally use standard web browsers for deployment, relying heavily on servers for processing, which simplifies deployment and maintenance. They access the Web Tier using HTTP/HTTPS and leverage web technologies like HTML, CSS, and JavaScript. Application Clients, on the other hand, are thick clients running standalone Java applications on the client machine. They directly interact with the Business Tier via RMI-IIOP and typically provide a richer GUI experience, making them suitable for complex applications requiring significant client-side processing .

In the J2EE architecture, Session Beans primarily implement synchronous business processes and logic. They can be stateful, maintaining conversational state with a client, or stateless, performing independent operations for each request. In contrast, Message-Driven Beans handle asynchronous tasks, often listening for and processing messages from a JMS queue or topic. This decoupling of business logic processing allows EJBs to manage different interaction patterns efficiently .

URL rewriting benefits include compatibility in environments where cookies are disabled, as it embeds session IDs in the URL itself. However, it also has drawbacks: it can clutter the URLs and requires server-side code to rewrite all links, potentially exposing session information if a URL with the session ID is bookmarked, thus posing security risks .

Component-based development in J2EE promotes reuse by allowing developers to build applications from self-contained, modular components like Servlets, JSPs, and Enterprise JavaBeans (EJBs). Each component encapsulates specific functionality, which can be reused across different applications, simplifying development and maintenance. By managing these components within containers that handle cross-cutting concerns, developers can focus on solving domain-specific problems without worrying about underlying infrastructure complexities .

You might also like