用JB8做,jboss服务器,编译通过,发布成功,用Servlet调用出如下错
Naming Exception caught:javax.naming.NameNotFoundException: ejb not bound
我的servlet为:
package yj;
import yj.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Properties;
public class HelloServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><head><title>the first EJB</title></head>");
try {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
HelloHome home = (HelloHome)ctx.lookup("HelloHome");
Hello yj = home.create();
out.println( yj.getHello() );
}catch(javax.naming.NamingException ne){
out.println("Naming Exception caught:"+ne);
ne.printStackTrace(out);
}
catch(javax.ejb.CreateException ce){
out.println("Create Exception caught:"+ce);
ce.printStackTrace(out);
}
catch(java.rmi.RemoteException re){
out.println("Remote Exception caught:"+re);
re.printStackTrace(out);
}
out.println("</body></html>");
}
}
各位帮帮看看吧
package 你的包;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.*;
public class HelloClient {
public static void main(String[] args) throws Exception {
Hello hello = null;
//Hello 为你的远程接口
try {
Context ctx = new InitialContext(System.getProperties());
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("HelloHome"),HelloHomeHome.class);
//HelloHome为你的远程home接口 “HelloHome”为你的远程Home jndi name
hello = home.create();
System.out.println(hello.getHello());
}catch (Exception e) {
System.out.println(e.toString());
}
}
}