| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 609 人关注过本帖
标题:求助:EJB调用
只看楼主 加入收藏
v_fire
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-7-15
收藏
 问题点数:0 回复次数:0 
求助:EJB调用

小弟刚开始学J2EE,安装完j2eesdk-1_4_03-windows.exe和Eclipse,从网上找了一个小例子“HelloWorld”作实践,使用deploytool部署完毕后,启动Client调用时出了个问题:RemoteHome home=(RemoteHome)javax.rmi.PortableRemoteObject.narrow(obj,RemoteHome.class);//程序在此处时,发现home=null。还请各位大虾帮帮看看:

Client.java

public class Client
{
public static void main(String[] args)
{
try
{
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
prop.setProperty("java.naming.provider.url","iiop://localhost:3700");
System.out.println("set prop success");
javax.naming.Context initContext=new javax.naming.InitialContext(prop);
System.out.println("get initContext success");
Object obj=initContext.lookup("ejb/hello");
if(obj!=null){
System.out.println("lookup jndi success");
}

RemoteHome home=(RemoteHome)javax.rmi.PortableRemoteObject.narrow(obj,RemoteHome.class);//程序在此处时,发现home=null。
if(home!=null){
System.out.println("ini remotehome success");
RemoteInterface remote=home.create();
String receiveFromRemote=remote.message("Hello,Remote Object!");
System.out.println("Client Received From Remote Object: \""+receiveFromRemote+"\"");
}else{
System.out.println("ini remotehome error");
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
}

附:
RemoteHome.java
public interface RemoteHome extends javax.ejb.EJBHome
{
RemoteInterface create()throws java.rmi.RemoteException,
javax.ejb.CreateException;
}


RemoteInterface .java

public interface RemoteInterface extends javax.ejb.EJBObject
{
public String message(String str)throws java.rmi.RemoteException;
}


RemoteObject.java

public class RemoteObject implements javax.ejb.SessionBean
{
public String message(String str)throws java.rmi.RemoteException
{
System.out.println("Remote Object Received From Client:\""+str+"\""); //打印(从客户端)接收到的字符串。
return "Hello,I'm Remote Object,I received your message:\'"+str+"\'"; //返回一应答字符串。
}

public RemoteObject() {}

public void ejbCreate() {}

public void ejbRemove() {}

public void ejbActivate() {}

public void ejbPassivate() {}

public void setSessionContext(javax.ejb.SessionContext sc) {}

}

搜索更多相关主题的帖子: EJB 
2006-07-15 11:25
快速回复:求助:EJB调用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024785 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved