I configure a connection pool in Tomcat5.5.12,like follows: <Context path="" docBase="/jsp-examples" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/bb1" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="administrator" password="123" driverClassName="sun.jdbc.odbc.JdbcOdbcDriver" url="jdbc:odbc:SMS"/> </Context>
Then I call this connection pool in a JSP file,the JSP file is follows: <[EMAIL PROTECTED] <%@<[EMAIL PROTECTED]> import="java.sql.*"%> <[EMAIL PROTECTED] import="javax.sql.DataSource"%> <[EMAIL PROTECTED] import="javax.naming.*"%> <html> <body> <% try{ Context initCtx=new InitialContext(); System.out.println("ok"); DataSource db = (DataSource)initCtx.lookup("java:comp/env/jdbc/bb1"); System.out.println("db="+db); Connection conn = db.getConnection(); System.out.println("conn="+conn); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM abc"); out.println("User-list"+"<br>"); while(rs.next()){ out.print(rs.getString(1)+"<br>"); } rs.close(); stmt.close(); conn.close(); }catch(Exception e){ out.print(e); } %> </body> </html> If I put this JSP file under a ordinary web directory,it runs well. But when I put this JSP file under Struts,then I call it,it raise follows errors: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context I am puzzled with it! I don't know why this JSP file can run well under Tomcat and don't run under Struts? Anybody knows how to solve it? Any idea will be appreciated! Best regards, phoenix