First, ready to work
1, EJB container: WebSphere5.1.2
2. Development Tools: WSAD5.1
Second, develop the HelloWorld EJB program.
1, home interface
Package ljb.ejb.helloworld;
Import java.rmi.remoteexception;
Import javax.ejb.ejbhome;
Import javax.ejb.createException;
Public interface helloejbhome extends ejbhome {
HelloejBObject Create () THROWS CREATEXCEPTION, RemoteException;
}
2, EJB object interface
Package ljb.ejb.helloworld;
Import java.rmi.remoteexception;
Import javax.ejb.ejbobject;
Public interface helloejbobject extends ejbobject {
Public String HelloWorld () throws RemoteException;
}
3, bean
/ *
* HelloWorld EJB CREATED by Liaojingbin 2004-10-25
* /
Package ljb.ejb.helloworld;
Import javax.ejb. *;
/ **
* @Author LJB
* /
Public class hellobean implements sessionbean {
Private INT i = 0;
Public void ejbcreate () {}
Public void ejbremove () {}
Public void ejbactivate () {}
Public void ejbpassiVate () {}
Public void setsessionContext (sessionContext CTX) {}
Public String HelloWorld ()
{
Return New String ("HelloWorld");
}
}
4, use JSP to call EJB
<% @ PAGE
Language = "java"
ContentType = "text / html; charSet = GBK"
PageEncoding = "GBK"
Import = "ljb.ejb.helloWorld. *, javax.naming. *, javax.rmi. *"
%>
HEAD>
<%
InitialContext ICT = New InitialContext ();
Object Obj = ICT.LOOKUP ("EJB / LJB / EJB / HelloWorld / Hellobean"); Helloejbhome Home = (Helloejbhome) PortableRemoteObject.narrow (Obj, Helljbhome.class);
HelloEJBOBJECT HELLOOBJ = home.create ();
Out.println (Helloobj.helloWorld ());
%>
Body>
Html>
5, Web.xml
XML Version = "1.0" encoding = "UTF-8"?>
servlet>
welcome-file-list>
EJB-REF>
web-app>
6. Ejb-jar.xml
XML Version = "1.0" encoding = "UTF-8"?>
"> ID = "EJB-JAR_ID">
session>
enterprise-beans>
ejb-jar>
6, Application.xml
XML Version = "1.0" encoding = "UTF-8"?>
module>
web>
module>
application>
After the test is passed in WSAD, you can release it on WebShpere. Here is the steps released. For novices, the following way is simple:
1, http:// localhost: 9090 / admin / enter the management console
2 Select: Applications / Install New Applications (before installing new applications, you must export your enterprise application as an EAR file in WSAD)
3, the following is installed and installed. Note: Binding enterprise bean to jndi name: Your bean will bind to a JNDI name, which is specified in EJB-JAR.XML, generally: EJB /. /. / xxxbean, my this is EJB / LJB / EJB / HELLOWORLD / HELLOBEAN
Mapping EJB Reference to Enterprise Bean: This is also a JNDI name: is the company's JNDI name of the company bean called by your web application, here is EJB / LJB / EJB / HelloWorld / Hellobean
After the installation is complete
Http: // localhost: 9080 / helloejbweb / hello.jsp
Output: HelloWorld, everything OK