Learn J2EE

xiaoxiao2021-03-06  55

This book is originally used by BES (Borland's server) and WebLogic (BEA server), but these two are more huge, so I have been replaced with JBoss, I believe everyone is also used.

EJB is the core component of the J2EE server. It provides transactions, data processing services, EJBs are divided into 3 components, which are remote interfaces, create interfaces to eat transaction, structure as shown:

The runtime process of the client program:

Start the client's program ---- Create a HelloHome object through the JNDI name ---- Create a Hello object ---- Access Sayello method

1

Import javax.ejb.ejbobject; import java.rmi.RemoteException;

Public interface hello extends EJBOBJECT {public String SayHello () throws RemoteException;} 2, create interface code as follows: / ** * Class Description: Create Interface * Class Name: * * Writer: Hu Fei * Write Date: June 2004 * / package hellostandardserver;

Import javax.ejb.ejbhome; import javax.ejb.createException; import java.rmi.RemoteException;

Public interface hellohome extends ejbhome {public hello create () throws createException, RemoteException;} 3, the code for the main file is as follows: / ** * Class Description: Bean Implementation is an implementation of the method, these methods have the above two Interface Provisions * class name: * * Writer: Hu Fei * Write Date: August 05, 2004 * / package hellostandardServer;

Import javax.ejb.sessionBean; import javax.ejb.sessionContext; import javax.ejb.createException;

Public class helloejb imports sessionbean {sessionContext sessionContext;

Public String Sayhello () {Return "Hello, welcome to the EJB learning process";

Public helloejb ()}

/ / Introduce the method of the sessionBean interface must declare

Public void ejbcreate () throws createException {system.out.println ("Create method activation.");}

Public void ejbremove () {system.out.println ("Remove method activates.");}

Public void ejbactivate () {system.out.println ("Active method activation.");}

public void ejbPassivate () {System.out.println ( "passivate activation method.");} public void setSessionContext (SessionContext sessionContext) {this.sessionContext = sessionContext; System.out.println ( "setsessioncontext activation method."); } 4. The client code is as follows: / ** *

Title: *

description: *

Copyright: Copyright (c) 2004 *

Company: * @author Hu Fei * @version 1.0 * /

Import java.util. *; import javax.naming. *; import javax.rmi. *;

Import HellostandardServer. *;

Public class testejb {public static void main (string [] args) {try {// jndi configuration, hardcoded to Java, implementation as an external property file // may be slightly different from the server to write PROPERTIES P = New Properties ); P.SetProperty ("java.naming.factory.initial," org.jnp.interfaces.namingContextFactory "); P.SetProperty (" java.naming.provider.URL "," localhost: 1099 "); // OUT Print JNDI Configuration P.List (System.out);

转载请注明原文地址:https://www.9cbs.com/read-116777.html

New Post(0)