Overview of The Java Platform Solution for EBusiness
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB
Outline w Big picture w Servlets w Java. Server Pages w EJB
Multi-Tiered Web-based application Browser HTML Browser XML Web Server EJB Server Servlet EJB DB JSP EJB DB
What are Servlets? w Extend HTTP Server n Dynamic content w Servlets are lightweight n n Run in web server process exploit Java security w Built on Java Platform n n Full access to Java APIs Easy to develop. Write once, run anywhere
HTTP Requests & Response w Client makes HTTP request w Request is resolved to Servlet w Container n n creates servlet invokes init() creates request and response objects invokes service() w Sevlet interact with response w Container replies to HTTP request w Container may n invoke destroy(), dispose servlet at anytime
A servlet example public class Hello. Servlet extends Http. Servlet { public void do. Get(Http. Servlet. Request request, Http. Servlet. Response response) { response. set. Content. Type("text/plain"); Print. Writer out = response. get. Writer(); out. println("<html>"); out. println("Hello World!"); out. println(" "); Jsp. Calendar clock = new Jsp. Calender(); out. println("Today is"); out. println("<ul>"); out. println("<li>Day of month: "); out. println(clock. get. Dayof. Month()); out. println("<li>Year: "); out. println(clock. get. Year()); out. println("/<ul>"); out. println("</html>"); } }
As a JSP page <html> Hello World! <jsp: use. Bean id="clock" class="calendar. Jsp. Calendar"> Today is <ul> <li>Day of month: <%=clock. get. Dayof. Month()%> <li>Year: <%=clock. get. Year()%> </ul> </html>
Java. Server Pages (JSP) w JSP builds on servlet semantics n “inside-out” servlets (JSP can be precompiled into Servlet to reduce start up time) w Benefits n Easier to author, separate presentation logic from business logic w Exploits: n n n server-side scripting templates encapsulation of functionality
Distributed Java Component Model -
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
Why is it HARD? w Difficult to reuse application code across n n hardware platforms software platforms servers databases w Service needs grow more complex n n n threading persistence transactions
What is EJB? w w 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
Distributed component models we are in heaven. . . IIOP CORBA Server Service RMI Client JRMP
The underlying mechanism. . .
Advantages of server side component model w Using pre-developed pieces of application w Transparent access to the distributed services, i. e. hiding the complexity of the technical environment w Components can be shared across the Enterprise w Using tools to wire components together
EJB Architecture
EJB Architecture
EJB Main Components w Client n n 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 w EJB Servers n n Contains and runs 1 or more containers Resource management l n process, thread, and connection pools Remote management API
EJB Main Components w EJB Containers n n Actually host the beans Provide naming (via JNDI), life cycle, persistence, security, transactions through call interception w EJB Components n n Are distributed, transactional, and secure Simple, single threaded, and non-re-entrant Developer or tool generated Contain business logic
Roles in developing EJB w Enterprise Bean provider w Application Assembler w Deployer w EJB Server Provider w System Administrator
Varieties of EJBs w Session beans n n Model application tasks Not shared, client specific Transient state Short lived l Example – an object holds the logic for purchasing product items i. e. buy. Product
Varieties of EJBs w Entity bean n n Model persistent resources Shared by clients Persistent state Long lived l Example – a product to be purchased in a shop
Programming basics – Classes and Interfaces w Remote interface n n Defines the bean’s business methods Extends javax. ejb. EJBObject w Home interface n n Defines the bean’s life cycle methods (creating, removing and finding a bean) Extends javax. ejb. EJBHome
Programming basics – Classes and Interfaces w Bean class n n 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 w Primary key n n Provides a pointer into the database Only entity beans need a primary key
The Unseen Pieces Client EJB home stub EJB Server home interface EJB home remote interface EJB Object EJB object stub remote interface RMI allows the downloadable stub bean class
Big picture again
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, Entity. Bean 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/Dist. Obj/ejbpre. htm here's a good EJB presentation
- Slides: 27