Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB."— Presentation transcript:

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

2 Outline  Big picture  Servlets  JavaServer Pages  EJB

3 Multi-Tiered Web-based application Browser HTML Browser XML Web Server Servlet JSP EJB Server EJB DB

4 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

5 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

6 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(" "); out.println("Hello World!"); out.println(" "); JspCalendar clock = new JspCalender(); out.println("Today is"); out.println(" "); out.println(" Day of month: "); out.println(clock.getDayofMonth()); out.println(" Year: "); out.println(clock.getYear()); out.println("/ "); out.println(" "); }

7 As a JSP page Hello World! <jsp:useBean id="clock" class="calendar.JspCalendar"> Today is Day of month: Year:

8 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

9 Distributed Java Component Model -

10 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

11 Why is it HARD?  Difficult to reuse application code across hardware platforms software platforms servers databases  Service needs grow more complex threading persistence transactions

12 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

13 Distributed component models - we are in heaven... CORBA Server Service RMI Server Service IIOP RMI Client JRMP

14 The underlying mechanism...

15 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

16 EJB Architecture

17

18 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

19 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

20 Roles in developing EJB  Enterprise Bean provider  Application Assembler  Deployer  EJB Server Provider  System Administrator

21 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

22 Varieties of EJBs  Entity bean Model persistent resources Shared by clients Persistent state Long lived Example – a product to be purchased in a shop

23 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

24 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

25 The Unseen Pieces Client EJB Server home interface EJB home home interface EJB home stub EJB Object remote interface bean class remote interface EJB object stub RMI allows the downloadable stub

26 Big picture again

27 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

28 The EJB Object  There’re a number of strategies that a vendor can use to implement the EJB object java.ejb.EJBObject Cabin Cabin_EJB_Object javax.ejb.EntityBean CabinBean a java.ejb.EJBObjectjavax.ejb.EntityBean CabinBeanCabin Cabin_EJB_Object b Java interface Java classextendsimplements

29 Example  Remote interface public interface Cabin extends javax.ejb.EJBObject { public void setDeckLevel(int level) throws RemoteException; public int getDeckLevel() throws RemoteException; }  Home Interface public interface CabinHome extends javax.ejb.EJBHome{ public Cabin create(int id) throws CreateException,RemoteException; public Cabin findByPrimaryKey(CabinPK pk) throws FinderException,RemoteException; }

30 Example – bean class public class CabinBean implements javax.ejb.EntityBean{ public int id; public int deckLevel; public void ejbCreate(int id){this.id = id;} public void ejbPostCreate (int id){} public int getDeckLevel(){return deckLevel;} public void setDeckLevel(int level){deckLevel = level;} public void setEntityContext(EntityContext ctx{} public void unsetEntityContext(){} public void ejbActivate(){} public void ejbPassivate(){} public void ejbLoad(){} public void ejbStore(){} public void ejbRemove(){} }


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

Similar presentations


Ads by Google