Top Banner
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB
27

Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Overview of The Java Platform Solution for E-Business Applications :

JSP, Servlet and EJB

Page 2: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Outline

Big pictureServlets JavaServer PagesEJB

Page 3: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Multi-Tiered Web-based application

Browser

HTML

Browser

XML

Web Server

Servlet

JSP

EJB Server

EJB

EJB

DB

DB

Page 4: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

What are Servlets?

Extend HTTP Server Dynamic content

Servlets are lightweight Run in web server process exploit Java security

Built on Java Platform Full access to Java APIs Easy to develop. Write once, run anywhere

Page 5: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

HTTP Requests & Response

Client makes HTTP request Request is resolved to Servlet Container

creates servlet invokes init() creates request and response objects invokes service()

Sevlet interact with response Container replies to HTTP request Container may

invoke destroy(), dispose servlet at anytime

Page 6: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

A servlet example

public class HelloServlet extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response) {

response.setContentType("text/plain");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("Hello World!");

out.println("<br>");

JspCalendar clock = new JspCalender();

out.println("Today is");

out.println("<ul>");

out.println("<li>Day of month: ");

out.println(clock.getDayofMonth());

out.println("<li>Year: ");

out.println(clock.getYear());

out.println("/<ul>");

out.println("</html>");

}

}

Page 7: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

As a JSP page

<html>

Hello World!

<br>

<jsp:useBean id="clock"

class="calendar.JspCalendar">

Today is

<ul>

<li>Day of month:<%=clock.getDayofMonth()%>

<li>Year: <%=clock.getYear()%>

</ul>

</html>

Page 8: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

JavaServer Pages (JSP)

JSP builds on servlet semantics “inside-out” servlets (JSP can be precompiled into Servlet to reduce

start up time)

Benefits Easier to author, separate presentation logic from business logic

Exploits: server-side scripting templates encapsulation of functionality

Page 9: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Distributed Java Component Model -

Page 10: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

The Problem

• Developing enterprise applications is HARD• Developing enterprise applications is EXPENSIVE• Enterprise applications are a NIGHTMARE TO MAINTAIN• Enterprise applications are COMPLEX TO ADMINISTER

Page 11: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Why is it HARD?

Difficult to reuse application code across hardware platforms software platforms servers databases

Service needs grow more complex threading persistence transactions

Page 12: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

What is EJB?

It’s server component model It’s part of Java platform for the enterprise It’s a specification (for software interoperability) It enables development and deployment of Java

applications that are:

• Distributed – via RMI• Scalable • Transactional • Secure

Page 13: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Distributed component models -we are in heaven ...

CORBAServerService

RMIServerService

IIOPIIOPIIOP

RMIClient

JRMP

Page 14: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

The underlying mechanism...

Page 15: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Advantages of server side component model

Using pre-developed pieces of application Transparent access to the distributed

services, i.e. hiding the complexity of the technical environment

Components can be shared across the Enterprise

Using tools to wire components together

Page 16: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

EJB Architecture

Page 17: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

EJB Architecture

Page 18: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

EJB Main Components

Client Any application or service requesting a service Can be written in any language Can’t access EJBs directly; must go through RMI and container Name lookup via JNDI

EJB Servers Contains and runs 1 or more containers Resource management

process, thread, and connection pools Remote management API

Page 19: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

EJB Main Components

EJB Containers Actually host the beans Provide naming (via JNDI), life cycle, persistence,

security, transactions through call interception EJB Components

Are distributed, transactional, and secure Simple, single threaded, and non-re-entrant Developer or tool generated Contain business logic

Page 20: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Roles in developing EJB

Enterprise Bean provider Application Assembler Deployer EJB Server Provider System Administrator

Page 21: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Varieties of EJBs

Session beans Model application tasks Not shared, client specific Transient state Short lived

Example – an object holds the logic for purchasing product items i.e. buyProduct

Page 22: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Varieties of EJBs

Entity bean Model persistent resources Shared by clients Persistent state Long lived

Example – a product to be purchased in a shop

Page 23: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Programming basics – Classes and Interfaces

Remote interface Defines the bean’s business methods Extends javax.ejb.EJBObject

Home interface Defines the bean’s life cycle methods (creating,

removing and finding a bean) Extends javax.ejb.EJBHome

Page 24: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Programming basics – Classes and Interfaces

Bean class Must have methods matching the signatures of

the methods defined in the remote interface Must have methods corresponding to some of the

methods in the home interface Primary key

Provides a pointer into the database Only entity beans need a primary key

Page 25: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

The Unseen Pieces

Client EJB Server

home interface

EJB homehome interface

EJB home stub

EJB Object

remote interface bean class

remote interface

EJB object stub

RMI allows the downloadable stub

Page 26: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Big picture again

Page 27: Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.

Several good introduction material on the web

http://java.sun.com/products/ejb/articles/multitier.html

This article shows a very good example on how to use EJB to develop multi-tier application!!! The example pretty much covers every thing (Session Bean, EntityBean and Servlet).

http://java.sun.com/products/ejb/faq.html

The FAQs on Sun EJB web site answered many general questions regarding to EJB.

http://internt.isk.kth.se/~enander/DistObj/ejb/ejbpre.htm

here's a good EJB presentation