6
 Java EE: An Introduction  JPA, EJB, JSF 1 Wednesday, January 27, 2010  J ava EE Components Applets: GUI app’s executed in a web browser. They use the Swing API to provide powerful user interfaces. Applications: programs executed on a client. Typically GUIs or batchprocessing programs that have access to all the facilities of the Java EE middle tier. W eb applications: app’s executed in a web container and respond to HTTP requests from web clients. Made of servlets, servlet lters, web event listeners, JSP pages, and JSF . Serv lets also support web service endpoints Enterprise Java Beans: containermanaged components for processing transacti onal business logic. They can be accessed locally and remotely through RMI  or HTTP for SOAP and RESTful web services  . 2 Wednesday, January 27, 2010 MVC Design Pattern The Model View Controller  MVC   design pattern separates the core business model functionality from the presentation and control logic that uses this functionality. The separation allows multiple  views to share the same enterprise data model, which makes supporting multiple clients easier to implement, test, and maintain. Source: Java BluePrints J2EE Patterns, MVC  http://java.s un.com/bluepri nts/patterns/M VC-detailed.ht ml  3 Wednesday, January 27, 2010  JEE app and the MVC architecture In a JEE application: The model business layer functionality represented by JavaBeans or EJBs The view  the presentation layer functionality represented by JSFs  the view   The controller Servlet mediating between model and view Must accommodat e input f rom various clients including HTTP requests from web clients, and… WML from wireless clients XML documents from suppliers Etc. 4 Wednesday, January 27, 2010

00 Intro to Jee

Embed Size (px)

Citation preview

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 1/6

 Java EE: An Introduction

 JPA, EJB, JSF

1Wednesday, January 27, 2010

 Java EE Components

• Applets: GUI app’s executed in a web browser. They use theSwing API to provide powerful user interfaces.

• Applications: programs executed on a client. Typically GUIs or

batchprocessing programs that have access to all the facilities of the Java EE middle tier.

• Web applications: app’s executed in a web container and respondto HTTP requests from web clients.

• Made of servlets, servlet filters, web event listeners, JSP pages,and JSF. Servlets also support web service endpoints

• Enterprise Java Beans: containermanaged components forprocessing transactional business logic. They can be accessedlocally and remotely through RMI  or HTTP for SOAP and

RESTful web services .2Wednesday, January 27, 2010

MVC Design Pattern

• The ModelView Controller MVC  design pattern separates

the core business modelfunctionality from thepresentation and control logicthat uses this functionality.

• The separation allows multiple views to share the sameenterprise data model, whichmakes supporting multipleclients easier to implement,test, and maintain.

Source: Java BluePrints J2EE Patterns, MVC http://java.sun.com/blueprints/patterns/MVC-detailed.html 

3Wednesday, January 27, 2010

 JEE app and the MVC architecture

• In a JEE application:

• The model business layer functionality represented by JavaBeans orEJBs

• The view  the presentation layer functionality represented by JSFs the view  

• The controller Servlet mediating between model and view 

• Must accommodate input from various clients including HTTP requests from web clients, and…

• WML from wireless clients

• XML documents from suppliers

• Etc.

4Wednesday, January 27, 2010

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 2/6

Model layer in a Web App

• Models the data and behavior behind the business process

• What it’s responsible for:

• Performing DB queries

• Calculating the business process

• Processing orders

• Encapsulation of data and behavior which are independentof presentation

5Wednesday, January 27, 2010

View layer in a Web App

• Display information according to client types

• Display result of business logic  Model 

• Not concerned with how the information was obtained, orfrom where  since that is the responsibility of Model 

6Wednesday, January 27, 2010

Controller in a Web App

• Serves as the logical connection between the user's

interaction and the business services on the back• Responsible for making decisions among multiple

presentations

• e.g. User's language, locale or access level dictates a di erentpresentation.

• A request enters the application through the control layer, which will decide how the request should be handled and what information should be returned

7Wednesday, January 27, 2010

Web Applications

• A web application is a dynamic extension of a web or applicationserver. Types of web applications:

• Presentationoriented

•  generates interactive web pages containing various types of markup language HTML, XHTML, XML, and so on  and dynamic content in response to requests.

• Serviceoriented

• A serviceoriented web application implements the endpoint of a web service.

• In Java EE platform, web components provide the dynamicextension capabilities for a web server.

• Web components are either Java servlets, web pages, web serviceendpoints, or JSP pages

8Wednesday, January 27, 2010

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 3/6

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 4/6

 JPA

• Relational model  i.e. RDBMS  vs. Object Oriented model i.e. Java  

• ObjectRelational Mapping  ORM 

•  Java Persistence API   JPA 

• An API above JDBC

• Can access and manipulate relational data from Enterprise Java Beans  EJBs , web components, and Java SE applications

• Includes an entity manager API to perform DBrelatedoperations like CRUD

• Includes JPQL, an objectoriented query language

13Wednesday, January 27, 2010

 JPA

• Objects vs. Entities

• Objects are instances that justlive in memory.

• Entities are objects that liveshortly in memory andpersistently in a database.

•  JPA map objects to a database via metadata that can be suppliedusing annotations or in an XMLdescriptor

• Annotations: The code of theentity is directly annotated with allsorts of annotations described in

the javax.persistence package.

@Entity

public class Book {

  @Id @GeneratedValue

private Long id;

  @Column(nullable = false)

private String title;

private Float price;

  @Column(length = 2000)

private String description;

private String isbn;

private Integer nbOfPage;

private Boolean illustrations;

// Constructors, getters, setters

}

14Wednesday, January 27, 2010

 JPA mapping 

15Wednesday, January 27, 2010

Enterprise Java Beans

• serverside components

• encapsulate business logic

• take care of transactions and security 

• used in building business layers to sit on topof the persistence layer and as an entry pointfor presentationtier technologies like JavaServer Faces   JSF .

• can be built by annotating a POJO that willbe deployed into a container

16Wednesday, January 27, 2010

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 5/6

Types of EJBs

• Session beans and Messagedriven Beans  MDBs 

• Session Beans are used to encapsulate highlevel businesslogic and can be...

• Stateless: contains no conversational state between methods, andany instance can be used for any client

• Stateful: contains conversational state, which must be retainedacross methods for a single user

• Singleton: A single session bean is shared between clients andsupports concurrent access

17Wednesday, January 27, 2010

EJB Example

@Stateless

public class BookEJB {

  @PersistenceContext(unitName = "chapter06PU")

private EntityManager em;

public Book findBookById(Long id) {

return em.find(Book.class, id);

}

public Book createBook(Book book) {

em.persist(book);

return book;

}

}

18Wednesday, January 27, 2010

Web pages and web servers

• Web servers

• Handles HTTP requests and sends a HTTP response typically 

HTML page• Default HTTP port: 80

• Typical servers: Apache  47, MS  21

• Netcraft Web Server Survey  December 2009 

• “Web languages”

• HTML

• CSS

•  JavaScript

19Wednesday, January 27, 2010

 JSF

•  JSF applications arestandard webapplications thatintercept HTTP via the Faces servlet andproduce HTML

20Wednesday, January 27, 2010

8/4/2019 00 Intro to Jee

http://slidepdf.com/reader/full/00-intro-to-jee 6/6

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"

 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

">

<html xmlns=""

http://www.w3.org/1999/xhtml"

  xmlns:h="

"http://java.sun.com/jsf/html">

<h:head>

<title>Creates a new book</title>

</h:head>

<h:body>

<h1>Create a new book</h1>

<hr/>

<h:form>

<table border="0">

<tr><td><h:outputLabel value="ISBN : "/></td>

  <td><h:inputText value="#{bookController.book.isbn}"/></td>

</tr>

<tr>

<td><h:outputLabel value="Title :"/></td>

<td><h:inputText value="#{bookController.book.title}"/></td>

</tr>

</table>

  <h:commandButton value="Create a book"

action="#{bookController.doCreateBook}" styleClass="submit"/>

</h:form>

<hr/>

<i>APress - Beginning Java EE 6</i>

</h:body></html>

21Wednesday, January 27, 2010

Packaging Java EE Web Apps

• A web application module contains:

• servlets, JSPs, JSF pages, and web services,

•as well as HTML and XHTML pages, Cascading Style Sheets CSS , JavaScripts, images, videos, and so on.

• All these artifacts are packaged in a jar file with a .war extension i.e., a war file, or Web Archive.

• WEB-INF/web.xml is the optional web deployment descriptor

• WEB-INF/ejb-jar.xml is the optional EJB Lite beansdeployment descriptor.

• WEB-INF/classes contains all the Java .class files

• WEB-INF/lib contains any dependent jar files.22Wednesday, January 27, 2010