サンプル

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

解決策
EJBHome をローカルで宣言しないでください。代わりに、フィールドとして宣言し (キャッシング)、サーブレットの init() メソッドでそれを代入してください。


public class BpSessionEJBServlet extends HttpServlet {
private BpSessionManagerHome sseHome = null; //EJB ホームをここにキャッシュします
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 }
}
}
}