4-Tier Model - PowerPoint PPT Presentation

persephone
4 tier model n.
Skip this Video
Loading SlideShow in 5 Seconds..
4-Tier Model PowerPoint Presentation
Download Presentation
4-Tier Model

play fullscreen
1 / 23
Download Presentation
4-Tier Model
286 Views
Download Presentation

4-Tier Model

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. 4-Tier Model Web Tier Client Tier EIS Tier Business Tier

  2. 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

  3. 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

  4. 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

  5. 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

  6. Remote Interface Remote Client EJB Home Interface Creating Enterprise Bean 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

  7. 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(); }

  8. 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) ; }

  9. 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); }

  10. /*********************** 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(); } }

  11. 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

  12. HTML JSP JavaBean index.html Save.jsp DetailURL.java Welcome.html SaveHandler.jsp CShiftLines.java MenuFrame.html CShiftLines.jsp Alphabetizer.java Alphabetizer.jsp KeyWordSearch.java Find.jsp SearchHistory.java FindHandler.jsp URLEventObject.java URLListener.java Source Codes

  13. Web Client save.jsp CShiftLines.jsp Alphabetizer.jsp find.jsp SaveHistory DetailURL CShiftLine saveHandle.jsp Alphabetizer findHandle.jsp Web Container KeyWordSearch EJB Container WebAddress AccountBean webaddressaccount

  14. JSP Syntax

  15. Locating the home interface Object objRef = ic.lookup("java:comp/env/ejb/TheWebAddressAccount"); WebAddressAccountHomehome = PortableRemoteObject.narrow(objRef, WebAddressAccountHome.class); • Creating an Enterprise Bean Instance WebAddressAccount joe = home.create( url_name, url_descript); • Invoking business methods WebAddressAccount findone = home.findByPrimaryKey(oneURLName); findone.getUrlDescript();

  16. 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

  17. Specifying a Resource Reference The WebAddressAccountBean code refers to the database as follows: private String dbName = "java:comp/env/jdbc/WebAddressAccountDB";

  18. Mapping Resource Referenceto JNDI Name

  19. 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 ");

  20. Mapping Resource Referenceto JNDI Name

  21. 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

  22. Running http://localhost:8000/kwicProject Change the default port number (8000) by editing the Config/web.properties file

  23. 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