发生NamingException,不知道为什么会错,帮忙指点原因!

SoHappy_PAN 2004-03-10 10:03:52
Hellojsp.war+
-index.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="
Hello,HelloHome,
javax.naming.*,
javax.ejb.*,
java.rmi.RemoteException,
java.rmi.Remote,
java.util.*
"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
try{
//String url = "http://" + request.getServerName() + ":" + request.getServerPort();

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");

Context ctx=new InitialContext(p);
%>
get the Context!
<%
Object objRef=ctx.lookup("java:comp/env/ejb/Hello");
HelloHome home=(HelloHome)javax.rmi.PortableRemoteObject.narrow(objRef,HelloHome.class);
Hello bean=home.create();
%>
get the Hello EJB!
<%
out.print(bean.getHello());
}catch(javax.naming.NamingException ne){ out.print("NamingException");
}catch(javax.ejb.CreateException ce){ out.print("CreateException");
}catch(java.rmi.RemoteException re){ out.print("RemoteException");
}
%>
the end!
</body>
</html>

运行之后的结果:
get the Context! NamingException the end!
...全文
94 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pan6best 2004-03-13
  • 打赏
  • 举报
回复
lookup("ejb/Hello");

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧