EJB Solution


In this section, the EJB and servlet codes have already been created using a third-party tool. You will learn how to use NAB 4.0 to import the EJBs and build the iCash application.

The credit card validation is implemented using a stateless session bean. The following EJB and servlet files are created using a third-party tool:

Type
Name
EJB home interface ICreditCardHome.java
EJB remote interface ICreditCardRemote.java
EJB implementation CrediteCardImpl.java
EJB property file ejb.properties
servlet iCashServlet.java


Import EJB

To import the EJB, perform the following steps:

1. Package all the EJB files - ICreditCardHome.java, ICreditCardRemote.java, CrediteCardImpl.java, ejb.properties as a creditcard.jar file.

2. Create a directory creditcard under the NAS root; and a subdirectory ejb under creditcard.

3. Copy the JAR file to the directory under the <NAS root>\creditcard\ejb.

4. Using NAB, select Import EJB(s) from the Project menu.

5. Select the JAR file, either by navigating or by entering the file name, and click Add.

NAB unpacks s the JAR file and places them in the correct folder. The Project Window displays the imported EJB files as shown in the following figure:

Compile EJB

To compile the EJB files, select Build Project from the Build menu.

NAB creates all the executable objects of the EJB, including stub and skeleton. The Project Window displays the compiled EJB files as shown in the following illustration:

Import and compile Servlet

To import and compile the servlet, perform the following steps:

1. Copy the servlet file - iCashServlet.java into the directory <NAS root>\creditcard

2. Using NAB, select Import Servlet(s) from the Project menu.

3. Select the servlet file, either by navigating or by entering the file name, and click Add.

The Project Window displays the imported servlet file as shown in the following illustration:

4. Select Compile File from the Build menu to compile this servlet.

Create a HTML page and add the servlet link

Finally, create a HTML page as shown in the following illustration:

and set the form's action as /NASApp/creditcard/iCashServlet.