ctx初始化不正确,试试这样
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);
//org.jnp.interfaces.NamingContextFactory这句话是jboss的,如果你用的是weblogic的话换成weblogic的代码
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);
//org.jnp.interfaces.NamingContextFactory这句话是jboss的,如果你用的是weblogic的话换成weblogic的代码
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
ctx = new InitialContext(props);
楼上上的!
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
ctx = new InitialContext(h);
LoginSessionLocalHome home = (LoginSessionLocalHome)ctx.lookup("sample.LoginSessionLocalHome");
LoginSessionLocal loginSessionLocal = home.create();
也不成,还是那个错误高手们快!
http://expert.csdn.net/Expert/TopicView1.asp?id=2223563
这个也是我的帖子,这个是不是就是发布成功了呢?
你如果真的要这样的话,你必须将*.war and *.jar打到一个*.ear中发布
这样就可在JSP中调用EJB的本地接口了。
哦----如果不行的话,web.xml你还是要加一些东西的如果你不这样你需要修改web.xml文件,或是使用远程接口
LoginSessionLocalHome home = (LoginSessionLocalHome)ctx.lookup("sample.LoginSessionLocalHome");
then
System.out.println("Test home exist =========" + home);
测试
寻找本地接口不是这样的吧??
LoginSessionLocalHome home = (LoginSessionLocalHome)ctx.lookup("LoginSession");
// LoginSession 是你的EJB 的名称是在jsp中调用ejb的本地接口,这样是不可以的??
可以的吧!!只要是在同一个 JVM 中!
请将jar包和war包打入ear包中,发布ear
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
ctx = new InitialContext(h);
LoginSessionLocalHome home = (LoginSessionLocalHome)ctx.lookup("sample.LoginSessionLocalHome");
这个方法也要加入的
Context ctx = null;
ctx = new InitialContext();
不对的