当前位置: 技术问答>java相关
那位英雄有EJB的例子什么的!
来源: 互联网 发布时间:2015-06-19
本文导语: 英雄!我再也经受不起,不会EJB的打击了~!有没有做过的工程什么的!发给俺看看,包括EJB的远程和home接口什么的!不能运行没有关系!只要例子是正确的就可以拉! 谢谢拉!!!! | 交流...
英雄!我再也经受不起,不会EJB的打击了~!有没有做过的工程什么的!发给俺看看,包括EJB的远程和home接口什么的!不能运行没有关系!只要例子是正确的就可以拉!
谢谢拉!!!!
谢谢拉!!!!
|
交流!
|
一个简单的无状态session EJB。好好部署肯定能运行
//myejbhome.java
import javax.ejb.*;
import java.rmi.*;
public interface myejbhome extends javax.ejb.EJBHome
{
myejbobj create() throws RemoteException,CreateException;
}
//myejbobj.java
import javax.ejb.*;
import java.rmi.*;
public interface myejbobj extends javax.ejb.EJBObject
{
public String doejb(String str) throws RemoteException;
}
//myejbclass.java
import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
public class myejbclass implements javax.ejb.SessionBean
{
public myejbclass(){
}
public void ejbCreate() throws RemoteException, CreateException {
}
public void ejbActivate() throws RemoteException {
}
public void ejbPassivate() throws RemoteException {
}
public void ejbRemove() throws RemoteException {
}
public void setSessionContext(SessionContext ctx) throws RemoteException {
}
public String doejb(String str)
{
System.out.println ("hello world ejb"+str);
return "girl";
}
}
//myejbclient.java
public class myejbclient
{
public static void main(String[] args)
{
try
{
javax.naming.Context initContext=new javax.naming.InitialContext();
Object obj=initContext.lookup("myejb");
myejbhome home=(myejbhome)javax.rmi.PortableRemoteObject.narrow(obj,myejbhome.class);
myejbobj remote=home.create();
String getfromejb=remote.doejb(" hi! ");
System.out.println(getfromejb);
}
catch(Exception e)
{
System.out.println (e);
}
}
}
//myejbhome.java
import javax.ejb.*;
import java.rmi.*;
public interface myejbhome extends javax.ejb.EJBHome
{
myejbobj create() throws RemoteException,CreateException;
}
//myejbobj.java
import javax.ejb.*;
import java.rmi.*;
public interface myejbobj extends javax.ejb.EJBObject
{
public String doejb(String str) throws RemoteException;
}
//myejbclass.java
import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
public class myejbclass implements javax.ejb.SessionBean
{
public myejbclass(){
}
public void ejbCreate() throws RemoteException, CreateException {
}
public void ejbActivate() throws RemoteException {
}
public void ejbPassivate() throws RemoteException {
}
public void ejbRemove() throws RemoteException {
}
public void setSessionContext(SessionContext ctx) throws RemoteException {
}
public String doejb(String str)
{
System.out.println ("hello world ejb"+str);
return "girl";
}
}
//myejbclient.java
public class myejbclient
{
public static void main(String[] args)
{
try
{
javax.naming.Context initContext=new javax.naming.InitialContext();
Object obj=initContext.lookup("myejb");
myejbhome home=(myejbhome)javax.rmi.PortableRemoteObject.narrow(obj,myejbhome.class);
myejbobj remote=home.create();
String getfromejb=remote.doejb(" hi! ");
System.out.println(getfromejb);
}
catch(Exception e)
{
System.out.println (e);
}
}
}