1 / 111

Java 2 Platform, Enterprise Edition (J2EE) An Overview

Java 2 Platform, Enterprise Edition (J2EE) An Overview. 蔡 文 能 交通大學資訊工程學系 tsaiwn@csie.nctu.edu.tw. What Is J2EE ?. Java 2 Enterprise Edition There are 3 different specifications within the Java framework (J2SE, J2ME, J2EE)

lloyd
Download Presentation

Java 2 Platform, Enterprise Edition (J2EE) An Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java 2 Platform, Enterprise Edition(J2EE)An Overview 蔡 文 能 交通大學資訊工程學系 tsaiwn@csie.nctu.edu.tw

  2. What Is J2EE ? • Java 2 Enterprise Edition • There are 3 different specifications within the Java framework (J2SE, J2ME, J2EE) • Created to provide a simple, unified standard for distributed applications through a component based application model • Specification is managed by a consortium of industry leaders

  3. Some useful online references • http://java.sun.com • http://java.sun.com/j2ee • http://java.sun.com/j2ee/tutorial/index.html

  4. J2EE and Other Java 2 Platform Editions Source: Computer, August 2000 J2EE, J2SE, J2ME

  5. J2EE and Other Java 2 Platform Editions J2EE, J2SE, J2ME Source: Sun Microsystems, Inc.

  6. Java Development and Runtime Environment Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

  7. Java 2 Platform Runtime Architecture Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

  8. Java 2 Platform, Standard Edition (J2SE 1.3) Source: Sun Microsystems, Inc., http://java.sun.com/j2se/1.3/

  9. Java 2 Platform, Standard Edition (J2SE 1.4) Source: Sun Microsystems, Inc., http://java.sun.com/j2se/1.4/

  10. Why J2EE ? • A stand alone program • Client/Server (2-Tier) • BBS, News, FTP, Telnet, … • Traditional (non-component) N-Tier Systems • 3-tier application: Browser – WEB Server – DBMS • New trend: • Component N-Tier Systems(J2EE Architecture) See figures on next slides

  11. 2-Tier Database Access • Client Tier – Presentation, Business Logic • Data Tier – Database Management Services Source: Sun Microsystems, Inc., JDBC 3.0 Specification

  12. Traditional(non-component) N-Tier Systems • Client Tier – Presentation Logic • Application Tier – Business Logic • Data Tier – Database Management Services Source: Sun Microsystems, Inc., JDBC 3.0 Specification

  13. Applet Container Fireware Enterprise Information Services EJB Container Web Container Connector Standalone Client JSP EJB Servlet Component N-Tier SystemsJ2EE Architecture EIS Tier Web Tier Business Tier Client Tier J2EE Server Machine Client Machine Database Server Machine

  14. J2EE Architecture (1/2) J2EE Component and Container Source: Sun Microsystems, Inc., J2EE Specification v1.3

  15. J2EE Architecture (2/2) • J2EE consists of three major parts: • Components Hold presentation and business logic • Containers Provide context for components • Connectors Provide access to legacy enterprise systems

  16. J2EE Components • Application clients • Applets • Web components • Servelets, Java Server Pages (JSP) • Portlet (see JSR168) • Business components • Enterprise Java Beans (EJB)

  17. J2EE ComponentApplet Component • An applet is a program written in the JavaTM programming language that can be included in an HTML page, much in the same way an image is included. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM). • An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.

  18. Applet pro vs. con • Applets: Java code that runs inside browser • Advantages: • Extends functionality on the client side • More complicated GUIs than w/ HTML or JavaScript • Computation can be off-loaded from server • Users don’t have to build, install, and configure • Disadvantages: • Download time • “Sandbox” limits functionality (unless signed) • Window management by browser

  19. J2EE ComponentWeb Component • Servlets • A servlet is a program that extends the functionality of a Web server. Servlets receive a request from a client, dynamically generate the response (possibly querying databases to fulfill the request), and then send the response containing an HTML or XML document to the client • JSP • The JavaServer Pages(JSP) technology provides an extensible way to generate dynamic content for a Web client. A JSP page is a text-based document that describes how to process a request to create a response

  20. Java Servlet Servlet Class wasn’t loaded into System Class Loader Load Servlet class Into System HTTP Request Browser Servlet Class was loaded Web Services Invoker HTTP Response Services

  21. Java Servlet • Java Servlet is the bridge for user to use Java solution in Web Server. • Java Servlet has better performance than CGI(Common Gateway Interface). • Java Servlet can use session to replace cookie and enhance security. • J2EE Server maintains the session for Java Servlets.

  22. JavaServer Pages (JSP) Compiler Java Source Code Java Bytecode Load Servlet class Into System New JSP Page JSP was modified Class Loader JSP isn’t loaded yet. HTTP Request (.jsp) Browser Web Services Invoker HTTP Response jspServices

  23. JavaServer Pages (JSP) • JSP has all features of Servlet. • JSP is a HTML like document. • JSP is designed for Web Page Developer. • JSP will change to Java Servlet source. • JSP is ran via Servlet mode.

  24. JavaServer PagesObjects • JSP has 9 objects which developer can use directly without new it. JSP Object java class scope request javax.servlet.ServletRequest request response javax.servlet.ServletResponse pag pageContext javax.servlet.jsp. PageContext page session javax.servlet.http.HttpSession session application javax.servlet.ServletContext application out javax.servlet.jsp.JspWriter page config javax.servlet.ServletConfig page page java.lang.Object page exception java.lang.Throwable page

  25. JSR168 Portlet Container JSR168 Portlet JSR168 Portlet Portlet and Portal Portal Server Browser • JSR168 • Java portlet standard • WSRP • Remote portlet communication protocol • Portals aggregate remote portlets HTTP WSRP (Web Services for Remote Portlets)

  26. The Reason For JDBC • Despite almost all databases supporting SQL, database vendors (Microsoft Access, Oracle etc.) provide proprietary (no standard) Application Programming Interfaces for sending SQL to the server and receiving results from it! • Languages such as C/C++ can make use of these proprietary APIs directly • High performance • Can make use of non standard features of the database • All the database code needs to be rewritten if you change database vendor or product • JDBC (Java DataBaseConnectivity) is a vendor independent API for accessing relational data from different database vendors in a consistent way CCTM: Course material developed by James King (james.king@londonmet.ac.uk)

  27. JDBC • JDBC provides an API that hides the vendor specific APIs by insertinga driver between the Java application and the database API • JDBC requires a vendor-specific driver • The driver converts calls from JDBC API to vendor’s API => performance penalty • The driver does not provide access to vendor specific functionality • The same Java application can be used with a different vendor’s database by simply switching JDBC driver and changing one line of Java code. • JDBC 1.0 is included inside JDK 1.1 or higher in a package java.sql • JDBC 2.0 and 3.0 require updated drivers and an additional package javax.sql CCTM: Course material developed by James King (james.king@londonmet.ac.uk)

  28. Rollback and Commit • By default connections to the database commit each update as soon as it is completed. • If you want to make a set of changes and only commit the aggregate result if nothing goes wrong auto commit needs to be switched off connection.setAutoCommit(false) You can then use connection.commit() to apply the changes connection.rollback() to undo changes since the last commit • You can switch auto commit back on using connection.setAutoCommit(true) CCTM: Course material developed by James King (james.king@londonmet.ac.uk)

  29. J2EE Compoent (1/2)EJB Component • Enterprise JavaBean (EJB) • The Enterprise JavaBeans (EJB) architecture is a server-side technology for developing and deploying components containing the business logic of an enterprise application. • Enterprise JavaBeans components, termed enterprise beans, are scalable, transactional, and multi-user secure. • EJB is an architecture for component-based transactional distributed computing.

  30. EJB Component (2/2) • An enterprise bean contains business logic that operates on the enterprise’s data. • Client access is mediated by a Container. • There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans.

  31. Enterprise Bean Objects • Session objects: for a single client, short-lived, …Stateful, Stateless • Entity objects: object view of data in the database, shared by multiple clients, long-lived, … • Message-driven objects: triggered by a single client message, short-lived, stateless, …

  32. Stateful Possess Internal State One per client Need to handle activation/ passivation Stateless Do not possess state Can be pooled to handle multiple clients Do not need to be passivated Stateful vs. Stateless Session Beans

  33. Container Manager Persistence Container responsible for database accesses/ controls Developer focuses on data use Bean Managed Persistence Developer must write code to handle database accesses/ controls Used for more specialized data mapping strategies Entity Beans: CMP vs. BMP

  34. Entity Bean Characteristics • Provides an object view of data in the underlying database • Shared across multiple users • Long-lived • Survives container crash

  35. To Implement an Enterprise Bean (1/2) • Any enterprise bean must define two interfaces and one or two classes • Remote interface • defines a bean’s external interface • must extend javax.ejb.EJBObject (which in turn extends java.rmi.Remote) • Home interface • The home interface defines a bean’s “life cycle” methods, eg. create bean, remove bean, find bean, etc. • must extend javax.ejb.EJBHome which also extends java.rmi.Remote

  36. To Implement an EJB (2/2) • Bean Class • The java class that actually implements the bean’s external interface, e.g. the bean class provides implementations for the bean’s “business methods” • An entity bean must implement the javax.ejb.EntityBean interface, while a session bean must implement the (you guessed it) javax.ejb.SessionBean. Both of these interfaces extend javax.ejb.EnterpriseBean • Primary Key • The primary key is a very simple class that provides a pointer into a database; Only entity beans need a primary key. This class must implment java.io.Serializable (so the entity bean can automatically be sent to persistent storage)

  37. EJB Container • A container is provided by the Application Server vendor to provide basic services that are required by J2EE specification. • An EJB programmer places their code here, and is assured a variety of basic services are available • This means the developer doesn’t have to code these services from scratch • Specification states which services must be supported but not how

  38. Basic Services Supplied by the EJB Container • Security • Transaction management • Remote Client Connectivity • Life Cycle Management • Database Connection Pooling

  39. More Services provided by container • The following basic services will be supported by all J2EE compliant products • RMI/RMI-IIOP • Resource Pooling • Thread Control • Presentation Logic • Persistence • Messaging • And more… IIOP: Internet Inter-ORB Protocol ORB: Object Request Broker

  40. Can’t Do in an EJB • Can’t use threads • Can’t use the AWT • Can’t act as network server • Can’t use java.io package • Can’t load native libray • Can’t use this as an argument or return value

  41. EJB Benefits Summary • Developing distributed applications in Java • Application developer is spared from following details • Transaction management • State management • Multi-threading • Connection pooling • Write once, run anywhere • Interoperability with other languages • Compatible with CORBA protocols

  42. J2EE Containers (1/2)Web Containers • Web Component Containers • 1. Servlet Containers • A servlet container provides network services (by which requests and responses are sent), decodes requests, and formats responses. All servlet containers must support HTTP as a protocol for requests and responses, but may also support additional request-response protocols such as HTTPS. • 2. JSP Containers • A JSP container provides the same services as a servlet container and an engine that interprets and processes a JSP page into a servlet. • 3. Web Containers • A Web container provides the same services as a JSP container and access to the J2EE service and communication APIs.

  43. J2EE Containers (2/2)EJB Containers • EJB Container • Enterprise beans are hosted by an EJB container. In addition to standard container services, an EJB container provides a range of transaction and persistence services and access to the J2EE service and communication APIs.

  44. Tomcat • Tomcat: Java-based web server + servlet container w/ JSP environment • Execution modes: • Standalone: default mode for Tomcat • Out-of-process add-on: web server plugin opens JVM outside web server; plugin and JVM communicate using IPC mechanism (TCP/IP sockets and special protocol)

  45. Tomcat and Apache  • Communication mechanism between Tomcat and Apache: web server adapter” or named as “connector” • Implemented as shared library (e.g., mod_jserv.so, mod_jk.so) • Uses/manages TCP connections • Uses the AJPV12/AJPV13 communication protocol

  46. J2EE Connectors • Contract between container and Enterprise Information Systems (EIS) • Proprietary and under the hood • Implementation is available with J2EE specification version 1.3 / 1.4

  47. J2EE Standard Services • HTTP/HTTPS • Java Transaction API (JTA) • Java Database Connection (JDBC) • Java Message Service (JMS) • Java Authentication and Authorization Service (JAAS) • J2EE Connector Architecture (JCA) • Others: RMI-IIOP, JavaIDL, JavaMail, JavaBeans Activation Framework (JAF), Java API for XML Parsing (JAXP) IIOP: Internet Inter-ORB Protocol

  48. The Solution: J2EE Application Model • J2EE application model partitions the work needed to implement a multi-tier service into two parts • the business and presentation logic (implemented by the application developer) • the standard system services provided by the J2EE platform. • The developer can rely on the platform to provide the solutions for the hard systems level problems of developing a middle-tier service.

  49. J2EE Application Model Source: Sun Microsystems, Inc., http://java.sun.com/j2ee/overview2.html

  50. Benefits of J2EE Application Model • The J2EE application model provides the benefits of Write Once, Run Anywhere™ portability and scalability for multi-tier applications. • This standard model minimizes the cost of developer training while providing the enterprise with a broad choice of J2EE servers and development tools.

More Related