j2ee annayi lc
TRANSCRIPT
![Page 1: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/1.jpg)
1
J2EETM : Why, What and How
![Page 2: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/2.jpg)
2
Objectives
• Why J2EE?
• What is J2EE?
• How to use J2EE?
![Page 3: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/3.jpg)
3
Motivation for J2EE
• Need for– New multi-tier enterprise computing model in
web environment– A way to bring in different elements of
enterprise application• Web interface design• Transaction processing• Meeting non-functional system requirements:
– Availability, reliability, enhanceability, performance, scalability, reusability, interoperability
• Timely development and deployment
Why J2EE?
![Page 4: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/4.jpg)
4
Two-tier Client/Server Architecture
Client Server
Why J2EE?
![Page 5: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/5.jpg)
5
Simple Web Client/Server• Interaction of two-tier architecture
• Client: simply accesses web pages through web browser
• Server: retrieves html documents
Why J2EE?
![Page 6: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/6.jpg)
6
CGI-based Web Client/Server
• Interaction of two-tier architecture• Client: uses service requiring 2ndary
storage• Server: manipulates forms, Database
updates, (primitive) electronic commerce• Fat Server/ Thin Client
Why J2EE?
![Page 7: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/7.jpg)
7
Java Applet-based Web Client/Server
• Interaction of two-tier architecture• Client: uses Java Applet for client-side
computation• Server: provides Applet bytecode• Fat Client/Thin Server
Why J2EE?
![Page 8: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/8.jpg)
8
Two-tier Client/Server Architecture
But what is the problem with this architecture?
Client Server
• So, important processing needs to be run on the server
• 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
Why J2EE?
![Page 9: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/9.jpg)
9
Drawbacks of two tier application architecture
• Easy to deploy, but difficult to enhance or upgrade
• Reusability of business and presentation logic difficult
• Not scalable
Why J2EE?
![Page 10: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/10.jpg)
10
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
Why J2EE?
![Page 11: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/11.jpg)
11
Separation of Business logic from Presentation logic
• Presentation logic : display• Business logic : what the company wants to do
Example: the distribution of different sales figures by diff dept (business logic) can be represented in many different ways (pie chart, bar graph, etc)
Why J2EE?
![Page 12: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/12.jpg)
12
Why J2EE?
• Simplifies the complexity of a building n-tier application
• Standardizes an API between components and application server container
• J2EE Application Server and Containers provide the framework services
![Page 13: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/13.jpg)
13
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
![Page 14: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/14.jpg)
14
Thin-client Multi-tiered Architecture
What is J2EE?
![Page 15: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/15.jpg)
15
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
![Page 16: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/16.jpg)
16
J2EE Components & Services
• Components- Java Servlets- JavaServer Pages (JSP)- Enterprise JavaBeans (EJB)
• Standard services & supporting technologies- Java database connectivity(JDBC) data access API- Java Messaging Service (JMS) (Remote Method Invocations (RMI))- Extensible Markup Languages(XML)- JavaIDL (Interface Description Language)- JavaMail- Java Security- CORBA technology- Design Patterns
![Page 17: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/17.jpg)
17
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)
![Page 18: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/18.jpg)
18
![Page 19: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/19.jpg)
19
The Big PictureWhat is J2EE?
![Page 20: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/20.jpg)
20
4-Tier Model
Client TierWeb Tier
Business Tier
EIS Tier
What is J2EE?
![Page 21: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/21.jpg)
21
Commercial Platforms
• J2EE SDK 1.6 (Sun) *
• WebLogic (BEA Systems)
• WebSphere (IBM)
• iPlanet (Sun & NetScape)
• JBoss (Open source)
What is J2EE?
![Page 22: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/22.jpg)
22
What is Application Server
Application servers enable the development of multi-tiered distributed applications. They are also called “middleware”
An application server acts as the interface between the database(s), the web servers and the client browsers
What is J2EE?
![Page 23: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/23.jpg)
23
Application Server: Key Services
![Page 24: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/24.jpg)
24
JBoss- Application Server
![Page 25: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/25.jpg)
25
J2EE Components
• Java Servlets
• JavaServer Pages (JSP)
• Enterprise JavaBeans (EJB)
What is J2EE?
![Page 26: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/26.jpg)
26
![Page 27: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/27.jpg)
27
![Page 28: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/28.jpg)
28
![Page 29: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/29.jpg)
29
![Page 30: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/30.jpg)
30
![Page 31: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/31.jpg)
31
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
What is J2EE?
![Page 32: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/32.jpg)
32
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
What is J2EE?
![Page 33: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/33.jpg)
33
JavaServer Pages (JSP)
• Text based documents describe how to process a request and create a response
• Contains HTML or XML and other JSP elements defined by JSP specification.
• Are Installed on web server • are web components that sits on top of
java servlet mode.
What is J2EE?
![Page 34: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/34.jpg)
34
JSP Advantages
• Performance– Runtime characteristics of servlets
• uses Lightweight threads: Doesn’t start new process for each request, Initialized once and persists in memory for multiple requests, cached
– Automatic recompilation of modified pages– Server side processing
• Programming– Emphasize use of reusable components– Write Once , Run Anywhere properties– Extensible through custom tag libraries
• Provides front end access mechanism to EJBs
What is J2EE?
![Page 35: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/35.jpg)
35
Parts of JSP Pages
Directive<%@ page import=“java.util.”, MVCApp.Cart, MVCApp.CartItem” %>
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();%>
What is J2EE?
![Page 36: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/36.jpg)
36
Parts of JSP Pages
• Expression
<td<% = ci.getTitle() %></td>
<td align =“right”><%=ci.getQuantity()%></td>• Implicit Objects
<% string action = request.getParameter(“action”) ; %>
What is J2EE?
![Page 37: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/37.jpg)
37
Enterprise Java Beans (EJBs)
• Entity Beans Represent persistent business Entity Persisted in storage system ( usually Database) Might contain Application logic intrinsic to entity
• Session Beans Perform work for individual clients on the server Encapsulate complex business logic Can coordinate transactional work on multiple entity
beans
What is J2EE?
![Page 38: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/38.jpg)
38
States and Persistence
• Session beans can be– Stateless- belong to client for duration of a method
call– Stateful- belong to client for duration of client
conversation
• Entity beans can have– Bean-managed persistence- The developer writes
SQL code to retrieve,store and update database– Container managed persistence- The developer
provide database mapping information that allows the container to manage persistence
What is J2EE?
![Page 39: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/39.jpg)
39
Example of EJB Application
• It consists of number of clients accessing session beans and entity beans
• Each Session bean provides specialized processing on behalf of client
e.g. Travel Agent session bean makes travel reservations while Flight Scheduler bean schedules planes to fly on various routes.
• Each Entity Bean represent different type of business entity.
e.g.Passengers, seats, planes, flights are entity beans
What is J2EE?
![Page 40: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/40.jpg)
40
Example: Travel AgencyWhat is J2EE?
![Page 41: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/41.jpg)
41
How to use J2EE ?
• Using J2EE SDK 1.6 to Design, Develop, Assemble and Deploy Applications
How to use J2EE?
![Page 42: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/42.jpg)
42
How to run J2EE application on J2EE SDK 1.6
• Preparation• Write and compile codes<Start J2EE SDK> to Assemble, Deploy, and Run the application
• Packaging– Creating the J2EE Application (.ear)– Creating the Enterprise Bean (.jar)– Creating the Web Client (.war)
• Deploying• Running
![Page 43: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/43.jpg)
43
Preparation
• Install J2EE SDK 1.6 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
![Page 44: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/44.jpg)
44
Creating Web Component
When web client such as browser communicates with J2EE application, it dose so through server-side objects called Web components
• Writes and compiles the source code• Bundles the .class, .jsp, .html files into WAR file
![Page 45: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/45.jpg)
45
An enterprise bean is a server-side component that contains the business logic of an application
• Write and compile the source code• Package the bean’s classes into EJB JAR file
– Remote Interface– Home Interface– Enterprise Bean Class
Creating Enterprise Bean
RemoteClient
RemoteInterface
HomeInterface
EJB
![Page 46: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/46.jpg)
46
![Page 47: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/47.jpg)
47
![Page 48: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/48.jpg)
48
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();
}
![Page 49: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/49.jpg)
49
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) ;
}
![Page 50: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/50.jpg)
50
Enterprise Bean Class
• WebAddressAccountBean.java– implements the business methods
public class WebAddressAccountBean implements EntityBean {
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);
}
![Page 51: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/51.jpg)
51
Start J2EE SDK to Assemble, Deploy, and Run the application
• Start Cloudscape database server. – C:\> cloudscape –start
• Start J2EE server – C:\> j2ee –verbose
• Start deploytool– C:\> deploytool
• Build the database table– C:\> cloudscape –isql
WebAddressAccount
urlName (PK)urlDescription
![Page 52: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/52.jpg)
52
![Page 53: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/53.jpg)
53
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
![Page 54: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/54.jpg)
54
Example: BonusApp
• Objective:
To calculate bonus for an employee
• 3-Tier Example using Session Bean
• 4-Tier Example using Entity Bean
![Page 55: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/55.jpg)
55
3 Tier Example: using session bean
1. Create HTML page
2. Create Servlet
3. Create the Session Bean
4. Compile the Session Bean and Servlet
5. Start the J2EE Application Server
6. Start the Deploy tool
7. Assemble the J2EE application
8. Specify JNDI Name and Root Context
9. Verify and Deploy the J2EE application
10. Run the J2EE application
![Page 56: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/56.jpg)
56
3 Tier Example: using session bean
• 3-tier– Html page– Servlet– Session Bean
![Page 57: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/57.jpg)
57
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>
![Page 58: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/58.jpg)
58
![Page 59: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/59.jpg)
59
BonusServlet.javapublic class bonusServlet extends HttpServlet {
![Page 60: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/60.jpg)
60
Create Session Bean: CalcHome, Calc, CalcBean
![Page 61: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/61.jpg)
61
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.
![Page 62: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/62.jpg)
62
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.
![Page 63: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/63.jpg)
63
CalcBean.java
The session bean class implements the SessionBean interface and provides behavior for thecalcBonus method. The setSessionContext and ejbCreate methods are called in thatorder by the container after BonusServlet calls the create method in CalcHome.
![Page 64: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/64.jpg)
64
Source Codes
CalcHome.javaBonusServlet.javabonus.html
Session BeanServletHTML
Calc.java
CalcBean.java
![Page 65: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/65.jpg)
65
Start the Application Server
• Start the Application Server
J2ee –verbose• Start the deploytool
deploytool
![Page 66: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/66.jpg)
66
Assemble the J2EE Application
1. Create a new J2EE application (BonusApp.ear).
2. Create a new enterprise bean (CalcBean.jar).
3. Create a new web component (Bonus.war).
4. Specify JNDI name for the enterprise bean (calcs).
5. Specify the Root Context for the J2EE application (BonusRoot).
![Page 67: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/67.jpg)
67
2. Create a New EnterpriseBean
![Page 68: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/68.jpg)
68
3. Create a new web component (Bonus.war).
![Page 69: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/69.jpg)
69
JNDI Names and Resource References
• JNDI: Java Naming and Directory Interface• J2EE components locate objects by invoking the
JNDI lookup method
• The JNDI name of a resource and the name of the resource reference are not the same
• This approach to naming requires that you map the two names before deployment
![Page 70: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/70.jpg)
70
Specifying a Resource Reference
The WebAddressAccountBean code refers to the database as follows: private String dbName = "java:comp/env/jdbc/WebAddressAccountDB";
![Page 71: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/71.jpg)
71
Mapping Resource Referenceto JNDI Name
![Page 72: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/72.jpg)
72
Deploy the application
![Page 73: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/73.jpg)
73
Run the application
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.
![Page 74: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/74.jpg)
74
4 Tier Example: using entity bean/cooperating enterprise beans
• 4-tier– Html– Servlet– EJBs– Database
![Page 75: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/75.jpg)
75
Create Entity Bean: Bonus Home (Home interface), Bonus (Remote interface)
![Page 76: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/76.jpg)
76
Create Entity Bean: Bonus Home (Home interface), Bonus (Remote interface)
![Page 77: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/77.jpg)
77
4 Tier Example: using JavaServer Pages
• 4-tier– Client– JSP– EJBs– Database
JavaServer Pages (JSP) technology lets you put segments of servlet code directly into a static HTML page. When the JSP Page is loaded by a browser, the servlet code executes and the application server creates, compiles, loads, and runs a background servlet to execute the servlet code segments and return an HTML page or print an XML report.
![Page 78: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/78.jpg)
78
![Page 79: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/79.jpg)
79
4 Tier Example: Bonus.jsp
![Page 80: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/80.jpg)
80
Modifying the J2EE Application
• Change the source code • Recompile it• Redeploy the application
– Select Tools -> Update Files– Select Tools -> Deploy
Or– Select Tools -> Update And Redeploy
![Page 81: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/81.jpg)
81
Advantages & Disadvantages
• Advantages
• Disadvantages– Learning curve– Overhead of a layered architecture: no direct
communication between layers that are apart, affecting performance
– Moving target, i.e. upgraded versions
![Page 82: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/82.jpg)
82
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
![Page 83: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/83.jpg)
83
Conclusion: Research Issues
(Evolving)Vision still to be realized• Non-functional characteristics (enhanceability,
reusability, scalability, security, etc)
• Integration with other technologies such as CGI-programming and CORBA
• Fuller support for design patterns in software lifecycle
![Page 84: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/84.jpg)
84
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/
evangcentral/presentations/J2EE.pdf
![Page 85: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/85.jpg)
85
Design Patterns: Factory Method
• The Factory Method lets a class defer instantiation to subclasses
• The Factory Pattern promotes loose coupling by eliminating the need to bind application-specific classes into the code.
![Page 86: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/86.jpg)
86
Design Patterns: Factory Method
![Page 87: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/87.jpg)
87
Design Patterns: Factory Method
The equivalent code :The EJB Client code to talk to an EJB
import javax.naming.*;
public class EJBClient { public static void main (String[] argv) {
// get the JNDI naming context Context initialCtx = new InitialContext (); // use the context to lookup the EJB Home interface AccountHome home=(AccountHome)initialCtx.lookup("Account");// use the Home Interface to create a Session bean object Account account = home.create (10001, "Athul", 100000000.25d); // invoke business methods account.credit (200000000.25d); // remove the object account.remove (); }
}
![Page 88: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/88.jpg)
88
Design Patterns: FacadeThe JMS class hierarchy can be somewhat daunting at first glance. The relationships between the classes are straight forward, but they require a sequence of code that is often repeated within a JMS application.
![Page 89: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/89.jpg)
89
Design Patterns: facade
The JMS Connection and Session Types Depending upon the message-delivery paradigm you choose, your code must work with the correct ConnectionFactory, Connection, and Session classes. Each interface has a subclass for both the publish/subscribe (Topic) and point-to-point (Queue) message models.
![Page 90: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/90.jpg)
90
Design Patterns: Facade
Topic and Queue Subclasses
Topic and Queue extend the Destination abstract interface. Subsequently, MessageProducer and MessageConsumer have subclasses for both message models.
![Page 91: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/91.jpg)
91
Design Patterns: Facade
• The com.JMSFacade PackageThis is an example of importing and creating the JMS Facade class,
JMSManager: import com.JMSFacade;
import javax.jms.*;
public class myClass {
JMSManager jmsMgr = new JMSManager();
...
}
![Page 92: J2EE Annayi Lc](https://reader033.vdocuments.site/reader033/viewer/2022061107/544d651daf7959f0178b49fb/html5/thumbnails/92.jpg)
92
Core J2EE Pattern Catalog
http://java.sun.com/blueprints/patterns/index.html