1. Develop an ejb3 stateless sessionbean with remote and local interfaces.
If you cannot write it there, please give me more advice.
##############################
# Let's first introduce the star actors :#
##############################
Remote interface: remotehelloworld. Java
Local interface: localhelloworld. Java
Sessionbean: helloworldbean. Java
JNDI configuration: JNDI. properites
JSP: Hello. jsp
Package com. yourcompany. ejb3;
Public interface remotehelloworld {
Public String say (string name );
}
Package com. yourcompany. ejb3;
Public interface localhelloworld {
Public String say (string name );
}
Package com. yourcompany. ejb3;
Import javax. EJB. stateless;
Import javax. EJB. Remote;
Import javax. EJB. Local;
Import com. yourcompany. ejb3.remotehelloworld;
Import com. yourcompany. ejb3.localhelloworld;
@ Remote ({remotehelloworld. Class })
// The annotation indicates that remotehelloworld is the remote interface of this sessionbean.
@ Local ({remotehelloworld. Class })
// Note that localhelloworld is the local interface of this sessionbean
// @ Stateless annotation indicates that this is a stateless Session Bean
Public @ stateless class helloworldbean implements remotehelloworld, localhelloworld {
Public String say (string name ){
Return "this is a stateless ejb3 Session Bean, Author:" + name;
}
}
// The JNDI configuration tells your client to initialize the JNDI Naming Service.
JNDI. properties:
Java. Naming. Factory. Initial = org. jnp. Interfaces. namingcontextfactory
Java. Naming. Factory. url. pkgs = org. JBoss. Naming: org. jnp. Interfaces
Java. Naming. provider. url = localhost: 1099
Call in JSPCodeAs follows:
<%
Properties prop = new properties ();
Prop. Load (thread. currentthread (). getcontextclassloader (). getresourceasstream ("JNDI. properties "));
Initialcontext CTX = new initialcontext (PROP );
Remotehelloworld = (remotehelloworld) CTX. Lookup ("helloworldbean/remote ");
Remotehelloworld. Say ("christina007 [remote]");
Localhelloworld = (localhelloworld) CTX. Lookup ("helloworldbean/local ");
Localhelloworld. Say ("christina007 [local]");
%>
Running result:
This is a stateless ejb3 Session Bean, Author: christina007 [remote]
This is a stateless ejb3 Session Bean, Author: christina007 [local]
Summary steps:
1. Write the business logic interface of sessionbean.
2. Write sessionbean again. Remember to implement the business logic interface in sessionbean.