ctx = new InitialContext();
ctx不能new

解决方案 »

  1.   

    ctx = new InitialContext();
    Context envCtx = (Context)initCtx.lookup("相对于java:comp/env环境的名字"); 
    hello1=envCtx.lookup("hello");
      

  2.   

    ctx = new InitialContext();
    Context envCtx = (Context)initCtx.lookup("相对于java:comp/env环境的名字"); 
    hello1=envCtx.lookup("hello");

    楼上正解
      

  3.   

     Context initCtx = new InitialContext(); 
     Context envCtx = (Context)initCtx.lookup("java:comp/env"); 
     hello1= (String)envCtx.lookup("hello"); 
    对比一下,发现你少了 Context envCtx = (Context)initCtx.lookup("java:comp/env"); 这行代码