Beispiel

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 }
}
}
}

Lösung
Deklarieren Sie 'EJBHome' nicht lokal. Deklarieren Sie die Schnittstelle stattdessen als Feld (Caching) zu und ordnen Sie sie in der Methode init() des Servlets zu.


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 }
}
}
}