发生NamingException,不知道为什么会错,帮忙指点原因!
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!