Properties props =new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL,"127.0.0.1:1099");
System.out.println("start to create context!");
Context ctx = new InitialContext(props);
System.out.println("start ejb client test");
Object obj=ctx.lookup("Example");
ExampleHome home = (ExampleHome)PortableRemoteObject.narrow(obj,ExampleHome.class);
Example example = home.create();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL,"127.0.0.1:1099");
System.out.println("start to create context!");
Context ctx = new InitialContext(props);
System.out.println("start ejb client test");
Object obj=ctx.lookup("Example");
ExampleHome home = (ExampleHome)PortableRemoteObject.narrow(obj,ExampleHome.class);
Example example = home.create();
Context ctx=null;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
ctx = new InitialContext(p);
Object obj=ctx.lookup("ejb的绑定名");
ExampleHome home=(ExampleHome) PortableRemoteObject.narrow (obj,ExampleHome.class);
Example ejb=home.create();
public class ExampleEjbClient
{
public static Example getEjb() throws 异常
{
try{
Example home=(Example)HomeInterfaceFactory.create(Example.class,"XJTLMS/Example");
Exam Exam =home.create();
return Exam;
}
catch(CreateException e){
}
return null;
}
}在Jsp就可以直接引用ExampleEjbClient.getEjb().(你自己的方法)我的服务器用的是WebLogic,希望对你有帮助!
Context ctx=null;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
ctx = new InitialContext(p);
Object obj=ctx.lookup("ejb的绑定名");
ExampleHome home=(ExampleHome) PortableRemoteObject.narrow (obj,ExampleHome.class);
Example ejb=home.create();
{
public static Example getEjb() throws 异常
{
try{
Example home=(Example)HomeInterfaceFactory.create(Example.class,"XJTLMS/Example");
Exam Exam =home.create();
return Exam;
}
catch(CreateException e){
}
return null;
}
}