EJB programming & troubleshooting: How to call any EJB from a servlet/JSP

  1. Hi all,
         I'm facing the problem that , how to call an EJB from servlet or JSP page. What's the procedure to call an EJB from servlet or JSP page? Please give sample code here...
    Thanks in advance!!!!

    DSR Kumar.

    Threaded Messages (2)

  2. more than likely you would do an jndi lookup
  3. Response[ Go to top ]

    Hi, here is simple source code (use jndi)

    //get jndi context, if servlet is in same JVM else put
    //paramter Properties
    Context ctx = new InitialContext(null);

    //get Home interface of bean
    //narrow -retype
    BeanHome lhome = (BeanHome) javax.rmi.PortableRemoteObject.narrow(ctx.lookup("cz.train.Bean"), BeanHome.class);

    //get remote interface
    Bean lbean = lhome.create();

    //now you can call bussiness method on remote interface like

    Petr Zuska