Hi all,

 I am new to jboss and want to use EJB tech. I was trying to
 follow the 7 step tutorial (using the interest example) given and was
 successful in deploying the EJB in jboss and also was successful in
 running the client(InterestClient).
 
 I'm currently using Tomcat 3.2.1 with Jboss 2.1-beta under JDK1.3.

 But when I made a servlet to call my IntesestBean, the servlet in 
 Tomcat can not find IntesestHome, it trully puzzled me.
 
This is the source code of the Servlet EJB.java:
 
import java.io.*;
 
// Servlet stuff
import javax.servlet.*;
import javax.servlet.http.*;
 
// EJB stuff
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.web_tomorrow.interest.*;public class EJB extends HttpServlet {
 
  private Interest m_interest = null;
  private String sHome="";
 
public void init() {
    try {
        System.setProperty("java.naming.factory.initial",
        "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url",
        "localhost:1099");
      // Get a naming context
      InitialContext jndiContext = new InitialContext();
      sHome = "1";
 
      // Get a reference to the Interest Bean
      Object ref  = jndiContext.lookup("InterestBean");
      sHome = "2";
 
      // Get a reference from this to the Bean's Home interface
      InterestHome home = (InterestHome)
        PortableRemoteObject.narrow (ref, InterestHome.class);
 
   if (home == null) {sHome = "Home Null!";} else {sHome = "Not Null!";};
      // Create an Interest object from the Home interface
      m_interest = home.create();
    } catch(Exception e) {
     sHome = e.getMessage();
    }
  }
 
  public void doGet (HttpServletRequest request,
             HttpServletResponse response)
    throws ServletException, IOException {
 
    PrintWriter out;
    String title = "Servlet interface to EJB";
 
    // set content type and other response header fields first
    response.setContentType("text/html");
 
    // then write the data of the response
    out = response.getWriter();
 
    out.println("<HTML><HEAD><TITLE>");
    out.println(title);
    out.println("</TITLE></HEAD><BODY bgcolor=\"#FFFFFF\">");
    out.println("<H1>" + title + "</H1>");
 
    out.println("<H2>Calling EJB...</H2>");
    out.println("<H2>ok: " + sHome + "</H2>");
 
    try {
      if (m_interest == null) {
        out.println ("Could not connect to Interest bean. Is EJB Container running?");
      } else {
 
        // call the calculateCompoundInterest() method to do the calculation
        out.println ("Interest on 1000 units, at 10% per period, " +
          "compounded over 2 periods is:");
        out.println (m_interest.calculateCompoundInterest (1000, 0.10, 2));
      }
    } catch(Exception e) {
      out.println(e.toString());
    } finally {
      out.println("</BODY></HTML>");
      out.close();
    }
  }
}
 
this is the result when I go to http://localhost:8080/servlet/EJB:

Servlet interface to EJB

Calling EJB...

ok: 1

Could not connect to Interest bean. Is EJB Container running?
 
 
 
help me!
 
thanks a lot!
 
Sam Liu

Reply via email to