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

About This Presentation
Title:

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

Description:

out.println('Hello World!'); out.println(' br '); JspCalendar clock = new JspCalender ... Hello World! br jsp:useBean id='clock' class='calendar.JspCalendar' ... – PowerPoint PPT presentation

Number of Views:100
Avg rating:3.0/5.0
Slides: 28
Provided by: jian3
Learn more at: https://cse.buffalo.edu
Category:

less

Transcript and Presenter's Notes

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


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
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("lthtmlgt")
  • out.println("Hello World!")
  • out.println("ltbrgt")
  • JspCalendar clock new JspCalender()
  • out.println("Today is")
  • out.println("ltulgt")
  • out.println("ltligtDay of month ")
  • out.println(clock.getDayofMonth())
  • out.println("ltligtYear ")
  • out.println(clock.getYear())
  • out.println("/ltulgt")
  • out.println("lt/htmlgt")

7
As a JSP page
  • lthtmlgt
  • Hello World!
  • ltbrgt
  • ltjspuseBean id"clock"
  • class"calendar.JspCalendar"gt
  • Today is
  • ltulgt
  • ltligtDay of monthltclock.getDayofMonth()gt
  • ltligtYear ltclock.getYear()gt
  • lt/ulgt
  • lt/htmlgt

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?
  • Its server component model
  • Its part of Java platform for the enterprise
  • Its 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
...
IIOP
IIOP
IIOP
CORBAServerService
RMIServerService
RMIClient
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
EJB Architecture
18
EJB Main Components
  • Client
  • Any application or service requesting a service
  • Can be written in any language
  • Cant 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 beans business methods
  • Extends javax.ejb.EJBObject
  • Home interface
  • Defines the beans 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
EJB home stub
home interface
home interface
EJB home
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/multitie
    r.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/ejb
    pre.htm
  • here's a good EJB presentation

28
The EJB Object
  • Therere a number of strategies that a vendor can
    use to implement the EJB object

java.ejb.EJBObject
Cabin
javax.ejb.EntityBean
Cabin_EJB_Object
CabinBean
a
b
Java interface
Java class
extends
implements
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()
Write a Comment
User Comments (0)
About PowerShow.com