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) {//Manipule esta exceção de forma apropriada }
}
}
}

Solução
Não declare EJBHome localmente. Declare-o como um campo (armazenamento em cache) e designe-o no método init() do servlet.


public class BpSessionEJBServlet extends HttpServlet {
private BpSessionManagerHome sseHome = null; //Armazene o EJB Home em cache aqui
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) {//Manipule esta exceção de forma apropriada }
}
}
}