View
216
Download
0
Tags:
Embed Size (px)
Citation preview
CSE298
CSE300
CSE.RU-1.1
Distributed Object Computing and JavaDistributed Object Computing and Java--Web ApplicationWeb Application--
Pinglei ZhouJunming Wang Chaopeng Zhou
Computer Science & Engineering DepartmentThe University of Connecticut
191 Auditorium Road, Box U-155Storrs, CT 06269-3155
CSE298
CSE300
CSE.RU-1.2
MotivationMotivation
Web Application DevelopmentWeb Application Development Development of Internet and the WWW Traditional way for for dynamic Web
Application
Java Features Support Web ApplicationJava Features Support Web Application Servlet Enterprise JavaBeans JDBC Java and XML RMI …..
CSE298
CSE300
CSE.RU-1.3
Overview of the PresentationOverview of the Presentation
Overview Traditional Web Programming
Brief Introduction of Enterprise System With J2EE
Description and Evaluation Java-Support Description and Evaluation Java-Support Web ProgrammingWeb Programming
Conclusion and Future Work
CSE298
CSE300
CSE.RU-1.4
Traditional Web Programming & JavaTraditional Web Programming & Java
HTML ProgrammingHTML Programming
CGI ProgrammingCGI Programming
Scripting LanguageScripting Language
Active Server PagesActive Server Pages
Java-Based Web ProgrammingJava-Based Web Programming
CSE298
CSE300
CSE.RU-1.5
Generic Enterprise System & JavaGeneric Enterprise System & Java
Enterprise user Interface• AWT & SwingEnterprise Data Enabling• JDBC Distributing Enterprise Communications Enabling• RMICommon Services for Distributed Communications• JINIEnterprise Systems Assurance• Java Security ModelEnterprise Web Application• ServletEnterprise Model Components• EJB
CSE298
CSE300
CSE.RU-1.6
Why Dynamic Web Page ?Why Dynamic Web Page ?
The Web Page Is Based On Data The Web Page Is Based On Data Submitted by the UserSubmitted by the User
The Web Page Is Derived From Data The Web Page Is Derived From Data That Changes FrequentlyThat Changes Frequently
The Web Page Uses Information From The Web Page Uses Information From Corporate Database or Other Server-Side Corporate Database or Other Server-Side SourcesSources
CSE298
CSE300
CSE.RU-1.7
System ArchitectureSystem Architecture
Client Program
EJBs
Oracle Database
Servlet
JDBCJDBC
Servlet
JDBC
Middle Tier
Presentation Tier
Data Tier
CSE298
CSE300
CSE.RU-1.8
Servlet Examples UserServlet Examples User
Processing and/or store data Processing and/or store data submitted by over HTTPS using an submitted by over HTTPS using an HTML formHTML form
Allowing collaboration between Allowing collaboration between peoplepeople
Being a community of active agentsBeing a community of active agents
CSE298
CSE300
CSE.RU-1.9
Advantages Over Traditional CGIAdvantages Over Traditional CGI
EfficientEfficient
PowerfulPowerful
PortablePortable
SecureSecure
Each resquest each threadStore the program in momery after terminated
Talk Directly to the Web ServerMultiple servlets can share data
Standard Java API
A Servlet can be run by a Servlet Engine in a restrictive Sandbox
CSE298
CSE300
CSE.RU-1.10
Servlets vs. Applets
Servlets• Server-side Java programs
• Implements the javax.servlet.Servlet interface
Faceless
Applets• Client-side Java programs
• Subclassing the java.applet.Applet class
CSE298
CSE300
CSE.RU-1.11
Java Servlet Architecture
Host Machine A
Web Server Platform
Servlet Container
Configureation Service
Management Services
Request Handling
ResponseHandling
SessionManagement
ServletRequest
GenericServlet
ServletResponse
HttpServletRequest
HttpServlet
HttpServlet
Response
HttpSession
Cookie
Host Machine B
Web Client Web Client
Net W ork
Net W ork
Java ServletComponent
CSE298
CSE300
CSE.RU-1.12
Typical Servlet Life CycleTypical Servlet Life Cycle
Init
Service
Service
Service
Service
Service
ServiceService
Service
Destroy
Thread 1 Thread 2 Thread 3
CSE298
CSE300
CSE.RU-1.13
Servlet’s JobServlet’s Job
Read any data send by the user
Look up other information about the request that is embedded in the HTTP
Process the request and generate the results
Format the result inside a document
Send the document back to the client
CSE298
CSE300
CSE.RU-1.14
Three Tiers Architecture of Servlet Web Application
Servlet Engineer:Servlet class
Server:JWSDK
JDBC
OracleRelationalDatabase
JDK1.3
CSE298
CSE300
CSE.RU-1.15
Installation and SetupInstallation and Setup
Download and install JDK1.3Download and install JDK1.3
Download Java Servlet 2.2Download Java Servlet 2.2
Any Web Server That Support ServletAny Web Server That Support Servlet
http://java.sun.com/j2se/1.3/
http://java.sun.com/products/servlet/index.html
CSE298
CSE300
CSE.RU-1.16
Options for Web ServerOptions for Web Server
Apache TomcatApache Tomcat
Java Server Web Development Kit Java Server Web Development Kit (JSWDK)(JSWDK)
Sun’s Java Web ServerSun’s Java Web Server
Http://jakarta.apache.org
Http://java.sun.com/products/servlet/download.html
Http://freeware.thespere.com
CSE298
CSE300
CSE.RU-1.17
Basic Servlet StructureBasic Servlet Structure
Import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpelServlet extends HttpServlet {
public void init(ServletConfig config){
…..}
public void doGet(HttpServletRequest req, HttpServletResponse res ) throws ServletException , IOException {
…….}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException , IOException {
…….}
CSE298
CSE300
CSE.RU-1.18
Project Implementation-Three TiersProject Implementation-Three Tiers
Choose product(ProjectFrame.htm)
Create Query(CSE300DOC3.java)
Get Price Data from DB(DatabaseUtilities.javaDriverUtilities.javaDBResult.javaDataUtilities.java)
Present the priceinformation for choseninformation(CSE300DOC3.java)
Re-select
Provide Credit Information(CreditCard.htm)
Create Query(CSE300DOC04.java)
Present the Data toUser
Informationconfirmation
N
Y
CSE298
CSE300
CSE.RU-1.19
Project UML documentation
CSE298
CSE300
CSE.RU-1.20
JDBC and JavaJDBC and Java
What is JDBCWhat is JDBC Java Database Connectivity(JDBC) is implemented Java Database Connectivity(JDBC) is implemented
in the java.sql package. JDBC is the mechanism in the java.sql package. JDBC is the mechanism Java application and applets use to perform Java application and applets use to perform database access. database access.
Prior JDBC, the only way to access a database Prior JDBC, the only way to access a database from a Java program was to do the database access from a Java program was to do the database access in C, and use native methods to interface the C in C, and use native methods to interface the C code with Java. JDBC is intended to be a low-level code with Java. JDBC is intended to be a low-level API that is powerful enough to exploit most API that is powerful enough to exploit most features available on commercial relational features available on commercial relational database, but is simple enough to be used by all database, but is simple enough to be used by all levels of programmer. levels of programmer.
CSE298
CSE300
CSE.RU-1.21
JDBC technology is an API that lets you access JDBC technology is an API that lets you access
virtually any tabular data source from the Java virtually any tabular data source from the Java programming language. It provides cross-DBMS programming language. It provides cross-DBMS connectivity to a wideconnectivity to a widerange of SQL databases, and now, with the new range of SQL databases, and now, with the new JDBC API, it also provides access to other tabular JDBC API, it also provides access to other tabular data sources, such as spreadsheets or flat files.data sources, such as spreadsheets or flat files.
Benefit Benefit a developer can easily connect all corporate data a developer can easily connect all corporate data
even in a heterogeneouseven in a heterogeneous environment environment
JDBC and JavaJDBC and Java
CSE298
CSE300
CSE.RU-1.22
JDBC Technology Core features (part of the JavaTM 2 SDK, Standard Edition )
Feature Benefit
Result set enhancements Ease of programming
- Scrollable result set Ability to move a result set's cursor to a specific row. This feature is used by GUI tools and for programmatic updating
Updatable result set Ability to use Java programming language commands rather than SQL
New data types support Performance improvement (ability to manipulate large objects such as BLOB and CLOB without bringing them to the client from the DB server)
Batch updates Performance improvement (sending multiple updates to the DB for processing as a batch can be much more efficient than sending update statements separately
(http://www.javasoft.com/products/jdbc/features.html)
CSE298
CSE300
CSE.RU-1.23
JDBC Optional Package features (the javax.sql package)
(http://www.javasoft.com/products/jdbc/features.html)
JDBC Optional Package features (the javax.sql package)
Feature Benefit
JNDI support Ease of deployment (gives JDBC driver independence, makes JDBC applications easier to manage)
Connection pooling Performance improvement (a connection pool is a cache of database connections that is maintained in memory, so that the connections may be reused)
Distributed transactions
Important for implementing a distributed transaction processing system
JavaBeansTM (RowSet objects)
Send data across a network to thin clients, such as web browsers, laptops, PDAs, and so on
Access any tabular data source, even spreadsheets or flat files Make results sets scrollable or updatable when the JDBC driver
does not support scrollability and updatability Encapsulate a driver as a JavaBeans component for use in a GUI
CSE298
CSE300
CSE.RU-1.24
JDBC SecurityJDBC Security
Most Java security is centered on the applet and its capacities as code downloaded via the Internet or Intranet.
restricted in their access to the client machine and cannot read or write to files on that machine.
the only machine to which they are allowed to make a database connection is the machine from which they were downloaded.
These restrictions are relaxed when applets are run using applet runners such as the Java Appletviewer or the HotJava browser (Art Taylor 1997)
CSE298
CSE300
CSE.RU-1.25
JAVA and JDBCJAVA and JDBC
Rather than simply being used to “bring life to Rather than simply being used to “bring life to Web pages”, Java with database now can fill the Web pages”, Java with database now can fill the role of database –aware applications for a role of database –aware applications for a variety of needsvariety of needs currently common gateway interface (CGI)
applications are required to access databases from within Web browsers
Java applets with JDBC now have the potential to provide the functionality with more direct programming and the potential for improved performance.
CSE298
CSE300
CSE.RU-1.26
Java Applet Java Applet
A Java applet is a small, compact application A Java applet is a small, compact application downloaded as Java bytecodes over the Internet downloaded as Java bytecodes over the Internet by a World Wide Web browser.by a World Wide Web browser. programs represent one of the more common
uses of a Java application and can perform most of the functions of a regular Java application
An applet can either trusted or untrusted. A trusted applet has convinced the Java virtual machine that it can be trusted either by providing a cryptographic key or some other means. Once trusted, this applet could have access to local data.
CSE298
CSE300
CSE.RU-1.27
Java AppletJava Applet
An applet that has not provided some means of authentication is considered untrusted and would not have access to any local data. This applet could, however. Open a database connection back to the server from which it was downloaded.
An applet is designed to embedded in a Web page and then to supplement the HTML page being rendered by the browser.
Because an applet is a Java program, it is much easier to perform complex functions with an applet than with HTML, which is not a program language.
CSE298
CSE300
CSE.RU-1.28
Java AppletJava Applet
An applet can use GUI interface. Some GUI An applet can use GUI interface. Some GUI facilities are available as part of an HTML page, facilities are available as part of an HTML page, but Java allows a finer level of programming but Java allows a finer level of programming with the GUI controls.with the GUI controls.
Java applet make the programming of special-Java applet make the programming of special-purpose applications simpler and practically purpose applications simpler and practically eliminate the software distribution cost for these eliminate the software distribution cost for these programs. When combined with JDBC to programs. When combined with JDBC to enable access to relational databases, the enable access to relational databases, the possibility for special-purpose Java applet is possibility for special-purpose Java applet is greatly expanded. greatly expanded.
CSE298
CSE300
CSE.RU-1.29
Applet IssuesApplet Issues
There are also a number of issues to be considered. There are also a number of issues to be considered. These are especially issues that must be considered These are especially issues that must be considered
with all Web applications, specially performance with all Web applications, specially performance and security. and security. Access bandwidth over the Internet tends to
vary and impacts performance. An application that access a database through the Internet most likely will perform worse than the same application run over the local network.
An applet downloaded over the Internet operates within a fairly restrictive set of security rules. The object of these rules is to protect the interest of the user by protecting their client machine, but the programmer of the applet must consider these rules when designing the application.
CSE298
CSE300
CSE.RU-1.30
Applet IssuesApplet Issues
In general, normal unsigned applets are considered untrustworthy and are not allowed access to any local database or local files.
An applet that manages to convince the local Java machine that it can be trusted by providing a password or cryptographic key
CSE298
CSE300
CSE.RU-1.31
JDBC ApplicationJDBC Application
Java JDBC can be two-tiered (conventional Java JDBC can be two-tiered (conventional client-server) or three-tiered(partitioned client-server) or three-tiered(partitioned application).application).
While it is expected that many applications will While it is expected that many applications will make use of two-tiered application development, make use of two-tiered application development, there are advantages to the three-tiered there are advantages to the three-tiered approachapproach
StateImplementationInterfaceIdentifierPrincipals
CSE298
CSE300
CSE.RU-1.32
Two-tiered ApplicationTwo-tiered Application
There is a front- end portion of the application that There is a front- end portion of the application that request data. The data is stored on and retrieved request data. The data is stored on and retrieved from a server. The following figure is an example.from a server. The following figure is an example.
Tier Two
Database Instances
Tier OneClient
CSE298
CSE300
CSE.RU-1.33
Two-tiered ApplicationTwo-tiered Application
This approach has the benefit of moving front-end This approach has the benefit of moving front-end processing off the server where there is usually a processing off the server where there is usually a significant demand for CPU cycles and places significant demand for CPU cycles and places processing on the client where there are usually processing on the client where there are usually plenty of CPU cycles available.plenty of CPU cycles available.
It has the benefit of allowing data collection to be It has the benefit of allowing data collection to be performed in what is usually a rich GUI performed in what is usually a rich GUI environment such as windows. The GUI environment such as windows. The GUI environment requires CPU cycles and fast access to environment requires CPU cycles and fast access to the display device.To run such an application on the display device.To run such an application on the server could require CPU resources that could the server could require CPU resources that could be scarce on a busy server, and significant be scarce on a busy server, and significant bandwidth to the display device. bandwidth to the display device.
CSE298
CSE300
CSE.RU-1.34
Two-tiered ApplicationTwo-tiered Application
DisadvantageDisadvantage When an application must retrive a large
number of rows from the server and process the rows in application memory , then the traditional two-tiered, client-server model to suffer performance degradation.
CSE298
CSE300
CSE.RU-1.35
TTwo-tiered Realization of The CSCC wo-tiered Realization of The CSCC
Project Project
Tier Two
Database Instances
Client
Tier One
WebPageAppletData
CSE298
CSE300
CSE.RU-1.36
The WebpageThe Webpage
Dreamwaver3 Dreamwaver3
Firework3Firework3
Flash4Flash4
Photoshop5.5Photoshop5.5
Paintshop. Paintshop.
CSE298
CSE300
CSE.RU-1.37
The AppletThe Applet
Client Program
OracleDatabase
CustomerLogin
OrderData Search
Customer Database Update
CSE298
CSE300
CSE.RU-1.38
Advantages of this ApproachAdvantages of this Approach
Because the applet runs on the client, so Because the applet runs on the client, so the approach saves Server CPU cycles the approach saves Server CPU cycles and spaces.and spaces.
The cost of the realization is less The cost of the realization is less expensive than three tier’s approaches. expensive than three tier’s approaches. Because it saves one serverBecause it saves one server
CSE298
CSE300
CSE.RU-1.39
The disadvantages of the approachThe disadvantages of the approach
In a large enterprise, there is a need to control In a large enterprise, there is a need to control data access and enforce enterprise rules.data access and enforce enterprise rules.
If it is supported by the database server, some If it is supported by the database server, some portion of these rules can be enforced using portion of these rules can be enforced using stored procedures on the database server.stored procedures on the database server.
In more complicated business rules, using a In more complicated business rules, using a three tiered approach, a central application tier three tiered approach, a central application tier composed of remote methods and accessed using composed of remote methods and accessed using RMI can be used to enforce these rules. RMI can be used to enforce these rules. Creation and DisposalCreation and Disposal
CSE298
CSE300
CSE.RU-1.40
Future WorkFuture Work
Because of the equipment restriction, we did not try the application by putting applet and data to the same server.
If we use signed applet, it will spend about $400 to get the ID,certificate.So we can not try the signed applet on the Internet Explorer or Netscape. We only tested the program by using Appletviewer.
If in the future someone has chance , to test the approach in the same server. It will be fine.
CSE298
CSE300
CSE.RU-1.41
Benefits of Enterprise JavaBeansBenefits of Enterprise JavaBeans
Developer Architecture IndependentDeveloper Architecture Independent Write once, run anywhere (WORA)Write once, run anywhere (WORA) Establish Roles for Application DevelopmentEstablish Roles for Application Development EJBs Takes Care of Transaction ManagementEJBs Takes Care of Transaction Management Provides Distribute Transaction SupportProvides Distribute Transaction Support Creates Portable and Scalable SolutionCreates Portable and Scalable Solution Seamlessly Integrates with CORBASeamlessly Integrates with CORBA Provides for Vendor Specific EnhancementProvides for Vendor Specific Enhancement
CSE298
CSE300
CSE.RU-1.42
Modeling using Session and Entity EJBs
Use Session Beans for Application Logic
Use Session Beans as the only interface to the Client
Expect Little Reuse of Session Beans
Use Session Beans to Control the Workflow of a Group of Entity Beans
Use Entity Beans to develop a persistent object model
Use Entity Beans to Enforce Accuracy/Integrity of the Database
Insist on Reuse of Entity Beans
Model Domain Objects with a Unique Identity Shared by Multiple Clients
CSE298
CSE300
CSE.RU-1.43
The Architecture of this Application
J2EE ServerJ2EE Server
… ...
HTTPHTMLHTML
Database
JDBC
EJB Server
Session Beans
RMI/IIOP
Web Server
Servlets
Dynamically generated presentation
Entity Beans Entity BeansBusiness Logic
CSE298
CSE300
CSE.RU-1.44
Component Diagram of Enterprise Component Diagram of Enterprise BeansBeans
CSE298
CSE300
CSE.RU-1.45
Developing Web-based Application with Developing Web-based Application with J2EEJ2EE
Develop Entity BeansDevelop Entity Beans Develop Session BeansDevelop Session Beans Develop ClientsDevelop Clients Start up the Server & Deploy ToolStart up the Server & Deploy Tool Build the Bean and War Components (Define the Build the Bean and War Components (Define the
deployment descriptor)deployment descriptor) Deploy the ApplicationDeploy the Application
Specify the JNDI name and Web Context name Run the ApplicationRun the Application
CSE298
CSE300
CSE.RU-1.46
Developing & Deploying Entity BeansDeveloping & Deploying Entity Beans
Define Home InterfaceDefine Home Interface Define Remote InterfaceDefine Remote Interface Define a Primary Key ClassDefine a Primary Key Class Implement the Bean ClassImplement the Bean Class Compile the Above ClassesCompile the Above Classes Set up the Data Source to the DatabaseSet up the Data Source to the Database
With BMP, You Should Create the Database Manually
With CMP, the Container Create the Database at Deploying Time
Define the Deployment Descriptor with Define the Deployment Descriptor with DeploytoolDeploytool
Start J2EE Server and Your are Ready to DeployStart J2EE Server and Your are Ready to Deploy
CSE298
CSE300
CSE.RU-1.47
Define Home InterfaceDefine Home Interface
The Home Interface Defines the Life Cycle of an The Home Interface Defines the Life Cycle of an Enterprise BeanEnterprise Bean
It Extends javax.ejb.EJBHome InterfaceIt Extends javax.ejb.EJBHome Interface create<create<METHOD>(…)METHOD>(…) Methods Methods
The Return Type Must Be the Entity Bean’s Remote Interface Type
find<METHOD>(…) Methods findByPrimaryKey(PrimaryKey pk) Method is
Mandatory for Entity Beans Home Methods (Only in EJB2.0)Home Methods (Only in EJB2.0)
CSE298
CSE300
CSE.RU-1.48
Home Interface SampleHome Interface Sample
// Sample entity bean home interface
import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Collection;
public interface CustomerHome extends EJBHome{
Customer create(String customerID,String name,String address,String password) throws CreateException, RemoteException;
public Customer findByPrimaryKey(String customerID) throws FinderException,RemoteException;
public Collection findByName(String name) throws FinderException,RemoteException;
}
CSE298
CSE300
CSE.RU-1.49
Define Remote InterfaceDefine Remote Interface
The Remote Interface Defines the Business Methods of an Enterprise Bean
It extends javax.ejb.EJBObject Interface For Every Method in the Remote Interface, There
is a Corresponding Method in the Bean Implementation
import javax.ejb.*;import java.util.Vector;import java.rmi.RemoteException;
public interface Customer extends EJBObject{// simple get and set methodspublic String getName() throws RemoteException;public void setName(String name) throws RemoteException;public String getPassword() throws RemoteException;public void setPassword(String password) throws RemoteException;public String getAddress() throws RemoteException;public void setAddress(String address) throws RemoteException;
}
CSE298
CSE300
CSE.RU-1.50
import java.io.Serializable;public class AccountPK implements Serializable{
public String accountID;public AccountPK(){}public AccountPK(String accountID){
this.accountID = accountID;}public int hashCode(){
return accountID.hashCode();}public boolean equals(Object other) {
if ((other == null) || !(other instanceof AccountPK))return false;
AccountPK otherPK = (AccountPK) other;return accountID.equals(otherPK.accountID);
}}
Define Primary Key Class for Entity Define Primary Key Class for Entity BeanBean
The Primary Key Class is Used to Uniquely The Primary Key Class is Used to Uniquely Identify an Object Reference to an Entity BeanIdentify an Object Reference to an Entity Bean
CSE298
CSE300
CSE.RU-1.51
Develop Entity Bean ClassDevelop Entity Bean Class
Implement the Business Logic MethodsImplement the Business Logic Methods Implement ejbCreate<METHOD>(…) Methods Implement ejbCreate<METHOD>(…) Methods
and ejbPostCreate<METHOD>(…) Methodsand ejbPostCreate<METHOD>(…) Methods Implement ejbFind<METHOD>(…) MethodsImplement ejbFind<METHOD>(…) Methods
ejbFindByPrimaryKey(PrimaryKey pk) Method is Mandatory Implement ejbHome<METHOD>(…) Methods Implement ejbHome<METHOD>(…) Methods
(Only in EJB2.0)(Only in EJB2.0) Implement EJB Call Back MethodsImplement EJB Call Back Methods
ejbActivate(): Called When the Bean is Activated ejbPassivate(): Called When the Bean is Passivated ejbLoad(): Forces the Bean to Load State from Database ejbStore() : Forces the Bean to Store State from Database ejbRemove(): Called When Client Calls Remove() setEntityContext(...): Called by Container on Creation unsetEntityContext(): Called by Container Before Being Removed
CSE298
CSE300
CSE.RU-1.52
Sample Entity Bean ClassSample Entity Bean Class// This is a Container Managed Persistence Beanimport …public class CustomerBean implements EntityBean{ protected EntityContext ctx; public String customerID; … … public CustomerBean(){} // business methods public String getCustomerName() throws RemoteException { return customerName; } public void setName(String name) throws RemoteException { this.customerName=customerName; } // create and finder methods public CustomerPK ejbCreate(…) throws CreateException,RemoteException { this.customerID=customeID; … ;return null; } public void ejbPostCreate(…) throws CreateException,RemoteException{} public CustomerPK ejbFindByPrimaryKey(CustomerPK primaryKey)throws … {} // EJB call back methods public void setEntityContext(EntityContext ctx)throws RemoteException {this.ctx=ctx;} public void unsetEntityContext() throws RemoteException { this.ctx = null; } public void ejbActivate() throws RemoteException {} public void ejbPassivate() throws RemoteException {} public void ejbStore() throws RemoteException{} public void ejbLoad() throws RemoteException{} public void ejbRemove() throws RemoteException{}}
CSE298
CSE300
CSE.RU-1.53
Developing & Deploying Session BeansDeveloping & Deploying Session Beans
Define the Home InterfaceDefine the Home Interface
Define the Remote InterfaceDefine the Remote Interface
Implement the Bean ClassImplement the Bean Class
Compile Your Code and Define the Deployment Compile Your Code and Define the Deployment Descriptor with DeploytoolDescriptor with Deploytool
Start up J2EE Server and You are Ready to DeployStart up J2EE Server and You are Ready to Deploy
CSE298
CSE300
CSE.RU-1.54
Develop War ComponentsDevelop War Components
Develop ServletsDevelop Servlets
Compile Your CodeCompile Your Code
Use Deploytool to Assemble Your War ComponentUse Deploytool to Assemble Your War Component Designate Servlet Class EJB References Role Security Transaction
CSE298
CSE300
CSE.RU-1.55
State Diagram for the ServletsState Diagram for the Servlets
Create a new customer and send mail to the user using Confirm session bean
Newuser Servlet
Charge a customer through Teller bean and display the data.
Display Servlet
Verify an account by querying Account
beanVerify Servlet
Storefront Servlet
Authenticate user by querying Customer entity bean
Login Servlet
Avail Servlet
Tell what data available by querying ClimateData bean
Return to the main page
Fig. 4 State digram for the servlet
CSE298
CSE300
CSE.RU-1.56
Develop ServletsDevelop Servlets
Locate the Bean Container Using JNDI & Locate the Bean Container Using JNDI & RMI/IIOPRMI/IIOP
Create the Bean if Necessary (When Business Method Required)
Use the Bean Dispose of the Bean (Call remove() Method)
CSE298
CSE300
CSE.RU-1.57
How the Client Locates the Home How the Client Locates the Home ObjectObject
Get or Create a JNDI Naming ContextGet or Create a JNDI Naming Context Use the Context to Lookup the EJB Home Object Use the Context to Lookup the EJB Home Object
Through RMI/IIOPThrough RMI/IIOP Use the Home Object to Create the Beans.Use the Home Object to Create the Beans.
try {// Get the JNDI naming contextContext initial = new InitialContext();// Use the context to lookup the EJB home interfaceObject objref = initial.lookup("TheAccount");// Use RMI/IIOP to get the EJB home interfaceaccountHome = (AccountHome)PortableRemoteObject.narrow(objref,AccountHome.class);
}catch(Exception e){
throw new ServletException(e.toString());}
CSE298
CSE300
CSE.RU-1.58
… ...public class NewuserServlet extends HttpServlet{ private CustomerHome customerHome; public void init() throws ServletException{ try { // Locate the Home Object
Context initial = new InitialContext();Object objref = initial.lookup("TheCustomer");
customerHome = (CustomerHome) PortableRemoteObject.narrow(objref,CustomerHome.class); } catch(Exception e){… … …} }
public void doGet((HttpServletRequest request,...)throws ServletException, IOException{
… … … try{ //Call finder methods or obtain Remote Reference customerHome.findByPrimaryKey(new CustomerPK(customerID)); customerHome.create(…); } … … …
Sample EJB ClientsSample EJB Clients
CSE298
CSE300
CSE.RU-1.59
Conclusions and Future ResearchConclusions and Future Research
ConclusionsConclusions Easy to Develop with J2EE Flexible Powerful
Future ResearchFuture Research New Feture in EJB2.0
Message-driven Bean
Persistence Provider
etc. Fully Explore EJBs.
JNDI, RMI, JSP, XML, JMS, Java IDL, JTS, JTA, JavaMail, and JAF
CSE298
CSE300
CSE.RU-1.60
System EvaluationSystem Evaluation
Learning vs. DevelopingLearning vs. Developing
Code LengthCode Length
Efficiency
Influence On Each Approach When Database Influence On Each Approach When Database ChangesChanges
Influence On Each Approaches When Business Rules Change
CSE298
CSE300
CSE.RU-1.61
Learning vs. DevelopingLearning vs. Developing
EJBsEJBs two months to learn while half a month to
develop
ServletServlet Have to know certain knowledge about Java.
AppletApplet The easiest to learn.
CSE298
CSE300
CSE.RU-1.62
Code LengthCode Length
EJBsEJBs Shortest code length, lots of duplicate codes.
ServletServlet Has the longest code length
AppletApplet Between EJBs and Servlet.
CSE298
CSE300
CSE.RU-1.63
Efficiency
EJBsEJBs Has the worst efficiency in the three
approaches
ServletServlet Faster than EJBs
AppletApplet Fastest among the three approaches.
Directly access the database by using the low-level interface
CSE298
CSE300
CSE.RU-1.64
Influence on Each Approach When Influence on Each Approach When Database Changes Database Changes
EJBsEJBs Simply re-designate the data source and re-
deploy the application, no source code change needed.
ServletServlet Have to change code and recompile and re-
deploy.
AppletApplet Have to change code and recompile and re-
deploy
CSE298
CSE300
CSE.RU-1.65
Influence On Each Approaches When Business Rules Change
EJBsEJBs Rewrite the session beans
ServletServlet Can update the rules but not flexible.
AppletApplet Difficult to update or enhance the rule
CSE298
CSE300
CSE.RU-1.66
ConclusionsConclusions
JDBC offers a database-independent means to JDBC offers a database-independent means to enable data for use in Java applicationenable data for use in Java application
Java Servlet architecture provides a component Java Servlet architecture provides a component container model that can result in a significant container model that can result in a significant amount of simplified HTTP communicationamount of simplified HTTP communication
EJB provides a standard component model for EJB provides a standard component model for developing distributing application as developing distributing application as components that operate inside of an EJB components that operate inside of an EJB containercontainer
CSE298
CSE300
CSE.RU-1.67
Future Work
JavaServer PagesJavaServer Pages Combination of markup with Java Code to
produce a dynamic web page
ServletServlet JINI and JavaSpace
Java RMI and IDLJava RMI and IDL Homogeneous & heterogeneous network
environments