struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "red phoenix" <rodphoe...@gmail.com>
Subject Why struts can't use Tomcat5 connection pool?
Date Sat, 01 Apr 2006 09:02:13 GMT
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:

<%@page <%@<%@page> import="java.sql.*"%>
<%@page import="javax.sql.DataSource"%>
<%@page 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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message