34
C O N S U L T I N G S Y S T E M S I N T E G R A T I O N O U T S O U R C I N G C S C. C O M C O N S U L T I N G S Y S T E M S I N T E G R A T I O N O U T S O U R C I N G C S C. C O M J2EE Basics

J2EE Basics

Embed Size (px)

Citation preview

Page 1: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 1/34

Page 2: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 2/34

Page 3: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 3/34

© Copyright CSC PLOENZKE AG

Distributed Multitiered Applications 

The J2EE platform uses a distributed multitiered application model for enterpriseapplications. Application logic is divided into components according to function, andthe various application components that make up a J2EE application are installed ondifferent machines depending on the tier in the multitiered J2EE environment towhich the application component belongs.

•Client-tier components run on the client machine.

•Web-tier components run on the J2EE server.

•Business-tier components run on the J2EE server.

•Enterprise information system (EIS)-tier software runs on the EIS server.

 

Page 4: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 4/34

© Copyright CSC PLOENZKE AG

Types of Tiers

Tiers are logical subdivisions addressing the “separation of concerns”. Tiersmay be described as the partitioning of the enterprise components based ontheir roles and responsibilities.

• Client Tier 

• Presentation Tier 

• Business Tier 

• Integration Tier 

• Data/Resource Tier 

Client Tier :-- Client tier is the user interface part of the enterprise application.This tier consists of components and containers that are helpful inprojecting information/data to the end user in a meaningfulmanner.Browser based clients are one of the examples of the client tier.

Presentation Tier:-- This tier houses those components and containers that

occupy intermediate position among the tiers. Their responsibilities are :--

1. Receive requests from the components of the client tier, process thesame and then appropriately route it to the appropriate component(s) inthe business tier.

2. Receive the results from the business tier, compute an appropriate viewand route the view back to the respective client.

Page 5: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 5/34

© Copyright CSC PLOENZKE AG

Types of Tiers

Business Tier:-- This tier houses the components and containers that carrybusiness logic crucial to the enterprise. A good Practice could be to shieldthese components so that the business logic is not exposed directly to theclients. The responsibility of this tier is to compute the business logic based onthe client request and, if necessary, apply changes to the database(s) at theback-end. It should then report the results to the presentation tier.

Integration Tier:-- This is an intermediate tier, connecting to the components of thebusiness logic tier in the front –end and the resource tier at the back-end.Thecomponents of this tier need to ensure an almost seamless integration with

different resources such as databases on the one side, and the components of the business logic tier, on the other.

Resource Tier:-- This is the logical and physical end of the tier system. This tier supports systems and applications that deal with the enterpriseinformation/data. The data/information in this tier are the data that need to bepersisted. The data/information referred to in this tier is often

accessed/modified/deleted by multiple processes/threads in an enterprisesituation. It is important that this data be accessed in a transactionalenvironment so that the data integrity is ensured.

 

Page 6: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 6/34

© Copyright CSC PLOENZKE AG

J2EE Components

J2EE applications are made up of components. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with itsrelated classes and files and that communicates with other components. The J2EEspecification defines the following J2EE components:

•Application clients and applets are components that run on the client.

•Java Servlet and JavaServer Pages (JSP ) technology components are webcomponents that run on the server.

•Enterprise JavaBeans (EJB ) components (enterprise beans) are businesscomponents that run on the server.

J2EE components are written in the Java programming language and are compiledin the same way as any program in the language. The difference between J2EEcomponents and "standard" Java classes is that J2EE components are assembledinto a J2EE application, are verified to be well formed and in compliance with theJ2EE specification, and are deployed to production, where they are run andmanaged by the J2EE server.

Page 7: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 7/34© Copyright CSC PLOENZKE AG

Client Components or Client Tier Components

A J2EE client can be a web client or an application client.

Web Clients 

A web client consists of two parts: (1) dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by webcomponents running in the web tier, and (2) a web browser, which renders thepages received from the server.

A web client is sometimes called a thin client . Thin clients usually do not querydatabases, execute complex business rules, or connect to legacy applications.

When you use a thin client, such heavyweight operations are off-loaded toenterprise beans executing on the J2EE server, where they can leverage thesecurity, speed, services, and reliability of J2EE server-side technologies.

Page 8: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 8/34© Copyright CSC PLOENZKE AG

Application Clients

Application Clients

An application client runs on a client machine and provides a way for usersto handle tasks that require a richer user interface than can be provided by amarkup language. It typically has a graphical user interface (GUI) created

from the Swing or the Abstract Window Toolkit (AWT) API, but a command-line interface is certainly possible.

Application clients directly access enterprise beans running in the businesstier. However, if application requirements warrant it, an application client canopen an HTTP connection to establish communication with a servlet runningin the web tier.

J2EE Server Communications

The client communicates with the business tier running on the J2EE server either directly or, as in the case of a client running in a browser, by goingthrough JSP pages or servlets running in the web tier.

Page 9: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 9/34© Copyright CSC PLOENZKE AG

Web Components and Presentation Tier Components

J2EE web components are either servlets or pages created using JSPtechnology (JSP pages). Servlets are Java programming language classesthat dynamically process requests and construct responses. JSP pages aretext-based documents that execute as servlets but allow a more natural

approach to creating static content.Static HTML pages and applets are bundled with web components duringapplication assembly but are not considered web components by the J2EEspecification. Server-side utility classes can also be bundled with webcomponents and, like HTML pages, are not considered web components.

Page 10: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 10/34© Copyright CSC PLOENZKE AG

Business Components or Business Tier Components

Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprisebeans running in the business tier. Figure shows how an enterprise beanreceives data from client programs, processes it (if necessary), and sends it

to the enterprise information system tier for storage. An enterprise bean alsoretrieves data from storage, processes it (if necessary), and sends it back tothe client program.

Page 11: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 11/34© Copyright CSC PLOENZKE AG

Enterprise Information System Tier 

The enterprise information system tier handles EIS software and includesenterprise infrastructure systems such as enterprise resource planning(ERP), mainframe transaction processing, database systems, and other legacy information systems. For example, J2EE application components

might need access to enterprise information systems for databaseconnectivity.

Page 12: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 12/34© Copyright CSC PLOENZKE AG

J2EE Containers

J2EE Containers

Normally, thin-client multitiered applications are hard to write because theyinvolve many lines of intricate code to handle transaction and statemanagement, multithreading, resource pooling, and other complex low-leveldetails. The component-based and platform-independent J2EEarchitecture makes J2EE applications easy to write because businesslogic is organized into reusable components. 

In addition, the J2EE server provides underlying services in the form of acontainer for every component type. Because you do not have to developthese services yourself, you are free to concentrate on solving the businessproblem at hand.

Page 13: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 13/34

© Copyright CSC PLOENZKE AG

Container Services

Containers are the interface between a component and the low-levelplatform-specific functionality that supports the component. Before a webcomponent, enterprise bean, or application client component can beexecuted, it must be assembled into a J2EE module and deployed into its

container.

•The J2EE security model lets you configure a web component or enterprise bean so that system resources are accessed only byauthorized users.

•The J2EE transaction model lets you specify relationships amongmethods that make up a single transaction so that all methods in onetransaction are treated as a single unit.

•JNDI lookup services provide a unified interface to multiple namingand directory services in the enterprise so that application componentscan access naming and directory services.

•The J2EE remote connectivity model manages low-levelcommunications between clients and enterprise beans. After anenterprise bean is created, a client invokes methods on it as if it werein the same virtual machine.

Page 14: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 14/34

© Copyright CSC PLOENZKE AG

Type of Containers

J2EE server :--The runtime portion of a J2EE product. A J2EE server provides EJB and webcontainers.

Enterprise JavaBeans (EJB) container :--Manages the execution of enterprise beans for J2EE applications. Enterprise beans and their container run on the J2EE server.

Web container :--Manages the execution of JSP page and servlet components for J2EEapplications. web components and their container run on the J2EE server.

Application client container :--Manages the execution of application client components.Application clients and their container run on the client.

Applet container :--Manages the execution of applets. Consists of a web browser and JavaPlug-in running on the client together.

Page 15: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 15/34

© Copyright CSC PLOENZKE AG

Design Patterns

A design pattern describes a proven solution to a recurring design problem,

placing particular emphasis on the context and forces surrounding theproblem, and the consequences and impact of the solution.

There are many good reasons to use design patterns. Here are three:

1)They are proven. You tap the experience, knowledge and insights of 

developers who have used these patterns successfully in their ownwork.

2) They are reusable. When a problem recurs, you don't have to inventa new solution; you follow the pattern and adapt it as necessary.

3) They are expressive. Design patterns provide a common vocabularyof solutions, which you can use to express larger solutions succinctly.

Page 16: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 16/34

© Copyright CSC PLOENZKE AG

J2EE Patterns

Pattern Name Description

Business Delegate [ACM01] Reduce coupling between Web and Enterprise JavaBeansTM tiers

Composite Entity [ACM01] Model a network of related business entities

Composite View [ACM01] Separately manage layout and content of multiple composed views

Data Access Object (DAO) [ACM01] Abstract and encapsulate data access mechanisms

Fast Lane Reader   Improve read performance of tabular data

Front Controller  [ACM01] Centralize application request processing

Intercepting Filter  [ACM01] Pre- and post-process application requests

Model-View-Controller   Decouple data representation, application behavior, and presentation

Service Locator  [ACM01] Simplify client access to enterprise business services

Session Facade [ACM01] Coordinate operations between multiple business objects in a workflow

Transfer Object [ACM01] Transfer business data between tiers

Value List Handler  [ACM01] Efficiently iterate a virtual list

View Helper [ACM01] Simplify access to model state and data access logic

Page 17: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 17/34

© Copyright CSC PLOENZKE AG

MVC Pattern

The goal of the MVC design pattern is to separate the application object

(model) from the way it is represented to the user (view) from the way in which

the user controls it (controller). 

Page 18: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 18/34

Page 19: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 19/34

© Copyright CSC PLOENZKE AG

MVC1

In GUIs, views and controllers often work very closely together. For example, a

controller is responsible for updating a particular parameter in the model that is

then displayed by a view. In some cases a single object may function as both a

controller and a view. Each controller-view pair is associated with only one

model, however a particular model can have many view-controller pairs. 

Page 20: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 20/34

© Copyright CSC PLOENZKE AG

MVC2

• Model = business data and rules, shared by all clients

• Controller = defines the application behavior,interprets user actions and maps them into actions

performed on the model• View = renders the contents of the Model

Page 21: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 21/34

© Copyright CSC PLOENZKE AG

Various Interactions between J2EE Components

CLIENTSCLIENTS

TIERTIER

External Clients fromINTERNET

(Browsers , WAP etc.)

Applets

Internal Clients fromINTRANET

(Browsers , Desk top

Applications etc.)

Applets, Javabeans

BACK ENDBACK END

TIERTIERJ2EE WEB APPLICATION SERVER TIERJ2EE WEB APPLICATION SERVER TIER

PRESENTATION LOGICPRESENTATION LOGIC

(Web Components)

BUSINESS LOGICBUSINESS LOGIC(EJB Container )

ENTERPRISE SERVICESENTERPRISE SERVICES

HTML

JDBC

XML

SERVLETS

JSP

WML

EJB

Java Beans

EJB

Java Beans

EJB

Java Beans

EJB

Java Beans

EJB

Java Beans

EJB

Java Beans

JNDI JMS JTS

RMI - IIOP

 Enterprise

Information

Systems

(Databases,

ERP,

Legacy Systems)

Page 22: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 22/34

© Copyright CSC PLOENZKE AG

Components and Components APIs

Java Servlet Technology:--Java servlet technology was created as a portable way

to provide dynamic, user-oriented content.

A servlet  is a Java programming language class that is used to extend the

capabilities of servers that host applications access via a request-response

programming model. Although servlets can respond to any type of request, they are

commonly used to extend the applications hosted by web servers. For such

applications, Java Servlet technology defines HTTP-specific servlet classes.

Two packages make up the Servlet architecture –•  javax.servlet and javax.servlet.http

1.  javax.servlet package contains the generic interfaces and classes that areimplemented and extended by all servlets.

2. javax.servlet.http package contains the classes that are extended when creatingHTTP specific servlets (servlets that respond to HTML)

At the heart of this, is the interface javax.servlet.Servlet – it provides the framework for allservlets. It defines five methods.

Page 23: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 23/34

© Copyright CSC PLOENZKE AG

A High Level Object Model of Servlet Framework A High Level Object Model of Servlet Framework 

<<Interface>>

 javax,.servlet.Servlet

init()

getServletConfig()

service()

getServletInfo()

destroy()

<<Interface>>

 javax,.servlet.ServletConfig

getIntiParameter()

getServletContext()

getInitParameterNames()

 javax,.servlet.GenericServlet

getServletContext()

getIntiParameter()

getInitParameterNames()log()

getServletInfo()

init()

getServletConfig()

service()

destroy()

 javax,.servlet.http.HttpServlets

doDelete( )doGet( )

doOptions( )

doPost( )

doPut( )doTrace( )service()getLastModified()

<<Interface>>

 javax,.io.Serializable

G i S l t d Htt S l t

Page 24: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 24/34

© Copyright CSC PLOENZKE AG

GenericServlet and HttpServlet

•Java servlets do not have a main () method, which is why all servlets mustimplement the javax.servlet.Servlet Interface.

•The HttpServlet class is extended from the GenericServlet class.

• The two objects that the service() method receives are the ServletRequest andServletResponse.

•ServletRequest Object holds the information that is being sent to the servlet.

•ServletResponse object is where we place the data we want to send back to theserver.

What happens when you extend HttpServlet – Do you implement the service()method??

- No, because it has already been implemented for you

G i S l t d Htt S l t

Page 25: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 25/34

© Copyright CSC PLOENZKE AG

GenericServlet and HttpServlet

ClientGenericServletGenericServlet

Service( )*Service( )*

Response

Request

Web serverWeb server

Client

HttpServlet

Response

Request

Web serverWeb server

Service( )

doDelete( )

doGet( )

doOptions( )

doPost( )

doPut( )

doTrace( )

*abstract method*abstract method

S l t Lif C l

Page 26: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 26/34

© Copyright CSC PLOENZKE AG

Servlet Life Cycle

The life cycle of a servlet is controlled by the container in which the servlet has

been deployed. When a request is mapped to a servlet, the container 

performs the following steps.

1. If an instance of the servlet does not exist, the web container 

a. Loads the servlet class.

b. Creates an instance of the servlet class.

c. Initializes the servlet instance by calling the init method.

1. Invokes the service method, passing request and response objects.

3. If the container needs to remove the servlet, it finalizes the servlet

by calling the servlet's destroy method. 

I it() th d

Page 27: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 27/34

© Copyright CSC PLOENZKE AG

Init() method

The init() method is where the servlet life begins.

1. It is called only once

2. It is called by the server immediately after the servlet is instantiated.

3. The init() method is defined as follows –

public void init(ServletConfig config) throws ServletException;

4. If, for some reason, the servlet cannot initialize the resources necessary tohandle requests, the init() method throws an exception.

5. The most common way of saving the object ServletConfig for later referencesis to have the init() call the super.init(), passing it the ServletConfig object.

Page 28: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 28/34

Destroy() method

Page 29: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 29/34

© Copyright CSC PLOENZKE AG

Destroy() method

1. This method signifies the end of the servlet’s life.

2. This is where any resources that were created in the init() should be cleanedup. (If you have an open database connection, you should close it here)

3. The signature of destroy() is –

public void destroy();

4. This is also a very good place to save any persistent information that will beused the next time the servlet gets loaded.

JSP (Java Server Pages)

Page 30: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 30/34

© Copyright CSC PLOENZKE AG

JSP (Java Server Pages)

1. Another set of server side Java APIs to enhance web server functionality.

2. JavaServerPages (JSP) technology allows web developers to rapidlydevelop dynamic web pages and easily maintain them.

3. JSP technology enables rapid development of web-based applications thatare platform independent and enjoy cross-web-server support.

4. Collecting data / presenting processed results to the client.5. Java snippets can be embedded into normal HTML code.

6. Closely linked interaction with JavaBeans API.

JSP Architecture

Page 31: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 31/34

© Copyright CSC PLOENZKE AG

JSP Architecture

  JSP pages are subject to two phases.

• Translation phase

• Request processing phase

 

Translation phase : The JSP page is translatedonly once, until the JSP page changes again.

Request processing phase : After the page

has been translated, the request processing

phase is handled by the servlet

JSP Translation

Page 32: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 32/34

© Copyright CSC PLOENZKE AG

JSP Translation

JSP Translated Servlet

Page 33: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 33/34

© Copyright CSC PLOENZKE AG

JSP Translated Servlet

Page 34: J2EE Basics

8/14/2019 J2EE Basics

http://slidepdf.com/reader/full/j2ee-basics 34/34