三.调用会话 Bean:sailorsyTestClient1
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
public class sailorsyTestClient1 {
private sailorsyHome sailorsyHomeObject = null;
//Construct the EJB test client
public sailorsyTestClient1() {
try {
//以下是客户端使用JNDI定位Home对象。
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("sailorsy");
//cast to Home interface
sailorsyHomeObject = (sailorsyHome) PortableRemoteObject.narrow(ref, sailorsyHome.class);
}
catch(Exception e) {
e.printStackTrace();
}
}
//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------
public sailorsyHome getHome() {
return sailorsyHomeObject;
}
//Main method
public static void main(String[] args) throws Exception{
sailorsyTestClient1 client = new sailorsyTestClient1();
sailorsyRemote sr=client.getHome() .create() ;
String s=sr.showname() ;
System.out.print(s);
// Use the getHome() method of the client object to call Home interface
// methods that will return a Remote interface reference. Then
// use that Remote interface reference to access the EJB.
}
}
以上的EJB在win2000+jbuilder5/jbuilder6+BAS4.5经过测试。
① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;
② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。