Java Reference
In-Depth Information
Example 23.5 Locating the home interface
//Look up home interface
InitialContext initctxt = new InitialContext();
Object obj = initctxt.lookup("ejb/Money");
MoneyHome homer = (MoneyHome) PortableRemoteObject.narrow(obj, MoneyHome.class);
We're putting this code in the init() method of a servlet; it could also
be in a test program, or in a JSP. It needs to happen only once for our servlet
(which is why we put it in the init() method) and then the connection can
be used many times, once for each contact with the bean.
We get to the actual bean this way:
Money mrbean;
mrbean = homer.create();
We then use the bean, making the calls on its remote interface (a Money
object, that extends EJBObject ) as if it were just a simple method call on an
ordinary class:
car = mrbean.save(20000.00, 0.04, 250.00);
The math is done in the actual SessionBean , out there in the network,
and the results are sent back to this application. Our application goes on to
display this number as part of an HTML page.
Then when we're done with the bean, we need to clean up:
mrbean.remove();
23.2.3
We will now package up the servlet, along with a simple startup page to invoke
it. We'll look at the WAR file and see how it's built.
Packaging the Servlet
23.2.3.1
The other JAR-like file in the EAR is the WAR file. Let's see what is in one of
those (Table 23.3).
Notice that the WAR file puts its XML descriptor not in the META-INF
directory but in a WEB-INF directory along with the classes.
What Is in the WAR File
Search WWH ::




Custom Search