Академический Документы
Профессиональный Документы
Культура Документы
TM
Objectives
Why J2EE? What is J2EE? How to use J2EE?
Why J2EE?
Why J2EE?
Client
Server
Why J2EE?
Why J2EE?
Why J2EE?
Interaction of two-tier architecture Client: uses Java Applet for client-side computation Server: provides Applet bytecode Fat Client/Thin Server
Why J2EE?
Then, Java needs to run on the server too to be more useful enterprise
The server is almost like what CGI-programming does Client: data access applying business logic and presentation of data (computation)
Server: serves only as service-database server, not application server web server Server Client
Why J2EE?
Easy to deploy, but difficult to enhance or upgrade Reusability of business and presentation logic difficult Not scalable
Why J2EE?
Vision of J2EE
An open standard Umbrella for anything Java-related For designing, developing, assembling, and deploying component-based enterprise applications Separation of business logic from presentation Reusability, enhanceability, scalability, interoperability
10
Why J2EE?
11
Why J2EE?
Simplifies the complexity of a building ntier application Standardizes an API between components and application server container J2EE Application Server and Containers provide the framework services
12
What is J2EE?
Defines the standard for developing multitier enterprise applications Simplifies enterprise applications by:
Basing them on standardized, modular components Providing a complete set of services to those components Handling many details of application behavior automatically, without complex programming
13
What is J2EE?
14
J2EE Tiers
Client Presentation
HTML or Java applets deployed in Browser XML documentations transmitted through HTTP Java clients running in Client Java Virtual Machine (JVM)
Presentation Logic
Servlets or JavaServer Pages running in web server
Application Logic
Enterprise JavaBeans running in Server
15
Advantages of Multi-tiers
Tiers separate functionality:
Presentation Logic, Business Logic, Data Schema
Easier upgrade since one tier can be changed without changing the rest Lower deployment and maintenance cost More flexible (can support changes), more extensible (can add functionality)
17
18
What is J2EE?
19
What is J2EE?
4-Tier Model
Web Tier
Client Tier
EIS Tier
Business Tier
20
What is J2EE?
Commercial Platforms
J2EE SDK 1.3 (Sun) * WebLogic (BEA Systems) WebSphere (IBM) iPlanet (Sun & NetScape) JBoss (Open source)
21
What is J2EE?
22
23
24
What is J2EE?
J2EE Components
Java Servlets
JavaServer Pages (JSP) Enterprise JavaBeans (EJB)
25
26
27
28
29
30
What is J2EE?
Overview of Servlets
Container-managed web components Replace Common Gateway Interface(CGI) or Active Server Pages (ASP) Generate dynamic response to requests from web based clients Synchronize multiple concurrent client request Serve as client proxies
31
What is J2EE?
Servlet Operation
Server is Java program that runs as separate thread inside servlet container. Servlet container is part of web server It interact with web client using response request paradigm
32
What is J2EE?
33
What is J2EE?
JSP Advantages
Performance
Runtime characteristics of servlets
uses Lightweight threads: Doesnt start new process for each request, Initialized once and persists in memory for multiple requests, cached
Programming
Emphasize use of reusable components Write Once , Run Anywhere properties Extensible through custom tag libraries
What is J2EE?
Declaration
<%! Iterator it = null; CartItem ci = null; Vector cpi = null;%>
Raw HTML
<html><head><title>Shopping Cart</title></head></html>
Action
<jsp:usebean id =Cart scope = session class = MVCApp.Cart/>
Scriplets
% Cpi = cart.getCartItems ( ); it = cpi.iterator(); While (it.hasNext()){ci= (Cart Item)it.next(); %>
35
What is J2EE?
36
What is J2EE?
Session Beans
Perform work for individual clients on the server Encapsulate complex business logic Can coordinate transactional work on multiple entity beans
37
What is J2EE?
What is J2EE?
39
What is J2EE?
40
41
Deploying Running
42
Preparation
Install J2EE SDK 1.3.1 on your system Set Environment Variables
JAVA_HOME
= root directory of J2SE SDK installation
J2EE_HOME
= root directory of J2EE SDK installation
PATH
= %PATH%;%JAVA_HOME%\bin;%J2EE_HOME%\bin
CLASSPATH
= %CLASSPATH%;%J2EE_HOME%\lib\j2ee.jar
43
44
46
47
Remote Interface
WebAddressAccount.java defines the business methods that a client may call. The business methods are implemented in the enterprise bean code
public interface WebAddressAccount extends EJBObject { public String getUrlName(); public String getUrlDescript();
48
Home Interface
WebAddressAccountHome.java defines the methods that allow a client to create, find, or remove an enterprise bean
public interface WebAddressAccountHome extends EJBHome {
public WebAddressAccount create(String urlName, String urlDescript); public WebAddressAccount findByPrimaryKey(String urlName) ;
49
public String getUrlName() { return urlName; } public String getUrlDescript() { return urlDescript; } public String ejbCreate( String urlName, String urlDescript) { insertRow( urlName, urlDescript); } public String ejbFindByPrimaryKey(String primaryKey) { result = selectByPrimaryKey(primaryKey); }
50
Start deploytool
C:\> deploytool
52
Packaging
Create an Enterprise Archive (EAR) file
ProjectApp.ear
Add Java Archive (JAR) files and Web Archive (WAR) files to the EAR
WebAddressAccountJAR: contains the enterprise bean files and related files ProjectWAR: contains the Web Component files and related files
53
Example: BonusApp
Objective: To calculate bonus for an employee
3-Tier Example using Session Bean 4-Tier Example using Entity Bean
54
56
bonus.html
<HTML> <BODY BGCOLOR = "WHITE"> <BLOCKQUOTE> <H3>Bonus Calculation</H3> <FORM METHOD="GET" ACTION=bonusServlet"> <P> Enter social security Number: <P> <INPUT TYPE="TEXT" NAME="SOCSEC"></INPUT> <P> Enter Multiplier: <P> <INPUT TYPE="TEXT" NAME="MULTIPLIER"></INPUT> <P> <INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET"> </FORM> </BLOCKQUOTE> </BODY> </HTML>
57
58
BonusServlet.java
public class bonusServlet extends HttpServlet {
59
60
CalcHome.Java
BonusServlet does not work directly with the session bean, but creates an instance of its home interface. The home interface extends EJBHome and has a create method for creating the session bean in its container.
61
Calc.java
When the home interface is created, the J2EE application server creates the remote interface and session bean. The remote interface extends EJBObject and declares the calcBonus method for calculating the bonus value. This method is required to throw javax.rmi.RemoteException, and is implemented by the CalcBean class.
62
CalcBean.java
The session bean class implements the SessionBean interface and provides behavior for the calcBonus method. The setSessionContext and ejbCreate methods are called in that order by the container after BonusServlet calls the create method in CalcHome.
63
Source Codes
HTML bonus.html
Servlet
BonusServlet.java
64
65
66
67
68
69
The WebAddressAccountBean code refers to the database as follows: private String dbName = "java:comp/env/jdbc/WebAddressAccountDB";
70
71
72
In the browser, type http://localhost:8000/BonusRoot/bonus.html Fill in a social security number Fill in a multiplier Click the Submit button. BonusServlet processes your data and returns an HTML page with the bonus calculation on it.
73
74
75
76
78
79
80
81
Conclusion : Summary
Need for server-side/enterprise processing with enhanceability, reusability, and scalability J2EE as a web-based, component-based multi-tiered client/server architecture Designing, developing, assembling, and deploying java applications using a platform
82
Integration with other technologies such as CGI-programming and CORBA Fuller support for design patterns in software lifecycle
83
Reference
http://java.sun.com/j2ee http://www.utdallas.edu/~chung/SA/2client .pdf http://sdmc.krdl.org.sg:8080/~judice/J2EE. pdf http://www.sun.com/developers/evangcent ral/presentations/j2eeoverview.pdf http://www.sun.com/developers/evangcent ral/presentations/J2EE.pdf
84
85
86
87
88
89
90
import javax.jms.*; public class myClass { JMSManager jmsMgr = new JMSManager(); ... }
91
http://java.sun.com/blueprints/patterns/index.html
92