Presentation is loading. Please wait.

Presentation is loading. Please wait.

17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.

Similar presentations


Presentation on theme: "17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components."— Presentation transcript:

1 17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components

2 17-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Create JavaServer Pages (JSP) clients for EJBs Use Enterprise JavaBeans (EJB) tags in JSPs Modify the configuration files in OracleAS 10g Containers for J2EE (OC4J)

3 17-3 Copyright © 2004, Oracle. All rights reserved. Overview JSP HttpServlet Request Web tier EJB tier Controller servlet Employees JSP Employees EJB To EIS HttpServlet Response

4 17-4 Copyright © 2004, Oracle. All rights reserved. Creating Remote Clients for EJBs To create a remote JSP client for an Enterprise JavaBean, perform the following steps : 1.Import the EJB home interface. 2.Override the jspInit() method. –Use the lookup() method to create a reference to the EJB. –Create the EJB remote object. 3.Retrieve the necessary parameters from the request object and pass the parameters to the EJB method. 4.Define a reference to the EJB in the web.xml file.

5 17-5 Copyright © 2004, Oracle. All rights reserved. Importing the EJB Home Interface Use the page directive to import the naming package and the home interface for the EJB:

6 17-6 Copyright © 2004, Oracle. All rights reserved. Create a Reference to the EJB To create an EJB reference, use the lookup method. Override the jspInit() method as follows: <%! Employees employees = null; public void jspInit() { try { InitialContext ic = new InitialContext(); EmployeesHome employeesHome = (EmployeesHome) PortableRemoteObject.narrow (ic.lookup("java:comp/env/Employees"), EmployeesHome.class); employees = employeesHome.create(); } catch (RemoteException ex) { ex.printStackTrace(); } } %>

7 17-7 Copyright © 2004, Oracle. All rights reserved. Passing Arguments to the EJB Method Calling an EJB method from a JSP expression evaluates the return value of the EJB method and displays it, as follows: Insert an Employee Number: <% String empno = request.getParameter("empno"); if (empno != null && empno.length() >0) { int i = Integer.parseInt(empno);%>

8 17-8 Copyright © 2004, Oracle. All rights reserved. Creating an EJB Reference To obtain an EJB reference for the Web tier components, create an element for the EJB in the web.xml file:

9 17-9 Copyright © 2004, Oracle. All rights reserved. Creating Local Clients for EJBs Creating JSP clients for local EJBs is similar to creating remote clients, with the following exceptions: The EJB object does not have to be cast to a PortableRemoteObject. Because the create() method does not throw a RemoteException exception, this does not have to be caught in the client. Instead of, an element is created in the client web.xml file.

10 17-10 Copyright © 2004, Oracle. All rights reserved. ejb-local-ref Element Right-click web.xml to create an EJB local reference.

11 17-11 Copyright © 2004, Oracle. All rights reserved. EJB Tags Oracle Application Server 10g provides a tag library that contains custom tags for referencing EJBs in JSPs: EJB Tag Purpose useHome Looks up the home interface for the EJB and creates an instance of it useBean Instantiates the EJB createBean Nests an EJB createBean tag within the useBean tag to create the EJB instance iterate Iterates through a collection of EJB instances

12 17-12 Copyright © 2004, Oracle. All rights reserved. useHome Tag The useHome tag has no body. The attributes are: id (required) type (required) location (required)

13 17-13 Copyright © 2004, Oracle. All rights reserved. useBean Tag The attributes of the useBean tag include: id (required) type (required) value scope

14 17-14 Copyright © 2004, Oracle. All rights reserved. createBean Tag The createBean tag contains only one required attribute named instance. " />

15 17-15 Copyright © 2004, Oracle. All rights reserved. iterate Tag The following are the attributes of the iterate tag: id (required) type (required) collection (required) max " max="100">

16 17-16 Copyright © 2004, Oracle. All rights reserved. Using the EJB Tags To use the EJB tags, perform the following steps: 1.Add the Oracle9 i AS library to your project in JDeveloper. a. Double-click the project and select libraries. b. Make sure that “Oracle9 i AS” is included in your project. 2.Use the OJSP EJB Library provided in the component palette to add the necessary tags to your JSP file. (This adds the bean as well as the taglib directive to the JSP.)

17 17-17 Copyright © 2004, Oracle. All rights reserved. Deploying an Application: Web Tier To deploy the Web tier components of a Java 2, Enterprise Edition (J2EE) application, perform the following steps: 1.Make sure that the ejb-ref or ejb-local-ref elements exist in the web.xml file. 2.Create a WAR deployment profile (.deploy ) in JDeveloper. 3.Right-click the.deploy file and select either of the following: –Deploy to WAR file –Deploy to OracleAS10g (where OracleAS10g is the name of your application server connection)

18 17-18 Copyright © 2004, Oracle. All rights reserved. Deploying an Application: EJB Tier 1.Make sure that the ejb-jar.xml file contains unique mappings for each EJB in the application. 2.Create a JAR deployment profile (.deploy ) in JDeveloper. 3.Right-click the.deploy file and select either of the following: –Deploy to JAR file –Deploy to OracleAS10g

19 17-19 Copyright © 2004, Oracle. All rights reserved. Deploying an Application: EAR File 1.Create an EAR file in JDeveloper. 2.Specify the EJB JAR and WAR files that are to be included in this EAR file. 3.Right-click the.deploy file and select either of the following: –Deploy to EAR file –Deploy to OracleAS10g

20 17-20 Copyright © 2004, Oracle. All rights reserved. Deploying from Oracle Enterprise Manager From the Enterprise Manager home page, click Home, then Application, and then select Deploy EAR file:

21 17-21 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Create JSP clients for EJBs Modify deployment descriptors for looking up an EJB client Deploy a J2EE application to Oracle Application Server 10g

22 17-22 Copyright © 2004, Oracle. All rights reserved. Practice 17-1 and 17-2: Overview These practices cover the following topics: Creating JSP clients that access EJBs Deploying a Web application to Oracle Application Server 10g

23 17-23 Copyright © 2004, Oracle. All rights reserved.

24 17-24 Copyright © 2004, Oracle. All rights reserved.

25 17-25 Copyright © 2004, Oracle. All rights reserved.

26 17-26 Copyright © 2004, Oracle. All rights reserved.

27 17-27 Copyright © 2004, Oracle. All rights reserved.

28 17-28 Copyright © 2004, Oracle. All rights reserved.


Download ppt "17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components."

Similar presentations


Ads by Google