试试: 
Context initCtx = new InitialContext();
 DataSource ds = (DataSource) envCtx.lookup("java:comp/env/jdbc/struts");

解决方案 »

  1.   

    JNDI配置详解:1. 确定你的SQL Server打了SP3包没有?如果打了补丁包,再查看它的端口是否被改成了2433
    2. 在server.xml里加上连接池的代码(这里就不多说了,网上一大把)
    3. 在context.xml里的<Context><\Context>中加上
       <ResourceLink global="jdbc/连接池名" name="jdbc/连接池名" type="javax.sql.DataSource"/>
    4. 在your website/WEB-INF/web.xml里加入如下代码
    <resource-ref>
          <description>DB Connection</description>
          <res-ref-name>jdbc/连接池名</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
    </resource-ref>
    5. 建立一个test.jsp文件测试你的连接池,并输出conn,看它的值是否为空,关键代码如下:
                Context envCtx = (Context) initCtx.lookup("java:comp/env");        
                DataSource ds=(DataSource)envCtx.lookup("jdbc/连接池名"); 
                Connection conn=ds.getConnection();
      

  2.   

    链接mssql出错。可能是端口等其它问题。