4-tier model client tier web tier business tier eis tier

23
4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Upload: amber-lee

Post on 27-Dec-2015

240 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

4-Tier Model

Client TierWeb Tier

Business Tier

EIS Tier

Page 2: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Run 4-Tier KWIC Project on J2EE Platform

• Preparation• Packaging

– Creating the J2EE Application (.ear)

– Creating the Enterprise Bean (.jar)

– Creating the Web Client (.war)

• Deploying• Running

Page 3: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Preparation

• 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 4: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Preparation

• 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 5: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 6: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

An enterprise bean is a server-side component that contains the business logic of an application

• Writes and compiles the source code• Packages the bean’s classes into EJB JAR file

– Remote Interface– Home Interface– Enterprise Bean Class

Creating Enterprise Bean

RemoteClient

RemoteInterface

HomeInterface

EJB

Page 7: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 8: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 9: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 10: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

/*********************** Database Routines *************************/ private void makeConnection() {

InitialContext ic = new InitialContext(); DataSource ds = (DataSource)

ic.lookup(“java:comp/env/jdbc/WebAddressAccountDB”); con = ds.getConnection(); }

private void insertRow ( String urlName, String urlDescript) {

PreparedStatement prepStmt = con.prepareStatement("insert into webAddressaccount values

( ? , ? )"); prepStmt.setString(1, urlName); prepStmt.setString(2, urlDescript); prepStmt.executeUpdate(); prepStmt.close();

}}

Page 11: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 12: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Source Codes

URLListener.java

URLEventObject.javaFindHandler.jsp

Find.jsp

KeyWordSearch.javaAlphabetizer.jsp

Alphabetizer.javaCShiftLines.jspMenuFrame.html

CShiftLines.javaSaveHandler.jspWelcome.html

DetailURL.javaSave.jspindex.html

JavaBeanJSPHTML

SearchHistory.java

Page 13: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

WebClient

save.jsp CShiftLines.jsp

saveHandle.jsp

Alphabetizer.jsp find.jsp

findHandle.jsp

WebAddressAccountBean webaddressaccount

DetailURLCShiftLine

Alphabetizer

KeyWordSearch

SaveHistory

Web Container

EJB Container

Page 14: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

JSP Syntax

Include <%@ page import="CShiftLines, DetailURL" %>

Declaration <%! private DetailURL url ; %>

Scriptlet <% Code fragment %>

Expression <%=url_name%>

Page 15: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

– Locating the home interfaceObject objRef =

ic.lookup("java:comp/env/ejb/TheWebAddressAccount");

WebAddressAccountHome home = PortableRemoteObject.narrow(objRef,

WebAddressAccountHome.class);

– Creating an Enterprise Bean InstanceWebAddressAccount joe = home.create( url_name, url_descript);

– Invoking business methodsWebAddressAccount findone

= home.findByPrimaryKey(oneURLName);

findone.getUrlDescript();

Page 16: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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 17: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Specifying a Resource Reference

The WebAddressAccountBean code refers to the database as follows: private String dbName = "java:comp/env/jdbc/WebAddressAccountDB";

Page 18: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Mapping Resource Referenceto JNDI Name

Page 19: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Specifying a Resource Reference

In lookup methods, the Web client refers to the home of an enterprise bean: Object objRef = ic.lookup("java:comp/env/ejb/TheWebAddressAccount ");

Page 20: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Mapping Resource Referenceto JNDI Name

Page 21: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Deploying

• Select Tools -> Deploy• In the JNDI Names dialog box, verify the names • In the WAR Context Root dialog box, enter kwicProject in the Context Root field, which will be part of the URL

Page 22: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

Running

http://localhost:8000/kwicProject Change the default port number (8000) by editing the

Config/web.properties file

Page 23: 4-Tier Model Client Tier Web Tier Business Tier EIS Tier

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