好,我先把错误信息打出来,下面我输入执行命令 java henryclient 以后错误如下
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial上面就是全部了还有,我的EJB方面应该是没有问题,原因有2:1,我的EJB远程接口是好了的,我用本地JSP调用远程接口没有错误。2,就算我把EJB那台电脑关了,或者开着,上面的错误都一样,我认为EJB绝对没有问题。情告诉我怎么解决
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial上面就是全部了还有,我的EJB方面应该是没有问题,原因有2:1,我的EJB远程接口是好了的,我用本地JSP调用远程接口没有错误。2,就算我把EJB那台电脑关了,或者开着,上面的错误都一样,我认为EJB绝对没有问题。情告诉我怎么解决
1. weblogic.jar不在classpath2.请替换如下代码:
原:
p.put("javax.naming.factory.initial","weblogic.jndi.WLinitialContextFactory");
p.put("javax.naming.provider.url","t3://192.168.0.2:7001");
改:
p.put("java.naming.factory.initial","weblogic.jndi.WLinitialContextFactory");
p.put("java.naming.provider.url","t3://192.168.0.2:7001");以第2种可能居大.
在CSDN也发了不少帖子了,可是到现在仍然没有解决。
可能使我太弱智的缘故吧,也可能问题就在某一个细小的地方,
很多人说的方法我都试过很多了,可问题依旧是这样。
看来还要继续啊,哦,对了,我出现的问题基本上和楼主是同一类型的。
用j2ee1.3本地测试成功,拿到另一台机器上就出异常.用weblogic也一样。
用j2ee1.4本地也出异常。根本无法成功。
都不知道该怎么办了,是不是我书看得少啊,哈哈哈哈哈。
Properties properties = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, EJBSERVERURL);
Context context = new InitialContext(properties);
String EJBSERVERURL = "t3://192.168.0.2:7001";
Properties properties = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, EJBSERVERURL);
Context context = new InitialContext(properties);可以试一试
<%@ page import="java.util.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="javax.rmi.PortableRemoteObject"%>
<%@ page import="testejb.*"%>
<html>
<head>
<title>TestPage</title>
</head>
<body bgcolor="#ffffff">
<%
Context context = null;
Sample sample = null;
//获取Context
try
{
String url = "t3://192.168.1.130:7001";
String user = null;
String password = null;
Properties properties = null;
out.println("debug | ready to set property ... <br/>"); properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null)
{
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
//
out.println("debug | ready to create context ... <br/>");
context = new InitialContext(properties);
}
catch (Exception ex)
{
out.println("<br/>创建Context对象出错:" + ex);
return;
} //查找Home接口,创建对象引用
try
{
//look up jndi name
Object ref = context.lookup("Sample");
//look up jndi name and cast to Home interface
SampleHome sampleHome = (SampleHome) PortableRemoteObject.narrow(ref, SampleHome.class); //
sample = sampleHome.create();
}
catch (Exception ex)
{
out.println("<br/>查找Home接口出错:" + ex);
return;
} //调用EJB对象
try
{
if (sample == null)
throw new Exception("EJBObject is null.");
//
Vector v_result = sample.getUserList();
while(!v_result.isEmpty())
out.println("<br/>\t" + v_result.remove(0));
}
catch (Exception ex)
{
out.println("调用EJB对象出错:" + ex);
}
%>
</body>
</html>