Example

public class BpSessionEJBServlet extends HttpServlet {
public void execute () throws ServletException{
Context ctx = null;
try {
java.util.Hashtable env = new java.util.Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, FACTORY);
ctx = new InitialContext(env);
Object homeObject = ctx.lookup ("EJB JNDI NAME");
BpSessionManagerHome sseHome = (BpSessionManagerHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)homeObject, BpSessionManagerHome.class);
}
catch (Exception e) {
throw new ServletException ("INIT Error: " + e.getMessage(),e);
}
finally {
try {
if (ctx != null)
ctx.close();
}
catch (Exception e) {//Handle this Exception Appropriately }
}
}
}

Solution
Do not declare EJBHome locally. Declare it as a field instead (caching) and assign it in the init() method of the servlet.


public class BpSessionEJBServlet extends HttpServlet {
private BpSessionManagerHome sseHome = null; //Cache the EJB Home Here
public void init () throws ServletException{
Context ctx = null;
try {
java.util.Hashtable env = new java.util.Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, FACTORY);
ctx = new InitialContext(env);
Object homeObject = ctx.lookup ("EJB JNDI NAME");
sseHome = (BpSessionManagerHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)homeObject, BpSessionManagerHome.class);
}
catch (Exception e) {
throw new ServletException ("INIT Error: " + e.getMessage(),e);
}
finally {
try {
if (ctx != null)
ctx.close();
}
catch (Exception e) {//Handle this Exception Appropriately }
}
}
}