tomcat 5.5.9 与之前的版本的配置方法不同
1.现在%tomcat home%/conf/catalina/localhost 下面添加一段独立的context xml段,命名为jasper.xml,例如<?xml version="1.0" encoding="UTF-8"?>
<Context path="/jasper" docBase="jasper" debug="1" reloadable="true" crossContext="true">
</Context>2.通过admin的界面(或手动在server.xml界面里进行配置)数据源,以sql2k为例,配置后的server.xml应该为<?xml version="1.0" encoding="UTF-8"?>
<Server>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      pathname="conf/tomcat-users.xml"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
      name="jdbc/Northwind"
      type="javax.sql.DataSource"
      password="*****"
      driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
      maxIdle="2"
      maxWait="5000"
      username="sa"
      url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind"
      maxActive="20"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="80"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxSpareThreads="75"
        maxThreads="150"
        maxHttpHeaderSize="8192">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost">
      </Host>
    </Engine>
  </Service>
</Server>3.在conf下面的context.xml文件中,</Context>之前加入 <ResourceLink name="jdbc/Northwind" global="jdbc/Northwind" type="javax.sql.DataSourcer"/>4.在你的web文件夹下面的WEB-INF中找到web.xml,在最后</web-app>之前加入<resource-ref>
      <description>Northwind Connection</description>
      <res-ref-name>jdbc/Northwind</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>5.保存,重启tomcat,这样,通过测试页面,就可以发现已经可以通过数据库连接池连上sql2ktest1.jsp<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<%@page import="javax.sql.*"%>
<%
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/Northwind");
Connection conn = ds.getConnection();
int counts=0;
String sql="select count(*) from orders";
PreparedStatement pst=conn.prepareStatement(sql);
ResultSet rst=pst.executeQuery();
while(rst.next()){
 counts=rst.getInt(1);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JNDI 测试</title>
</head><body>
<%=sql%><br>
pnrreg talbe's count is:<%=counts%>
</body>
</html>

解决方案 »

  1.   

    是在%tomcat home%/conf/catalina/localhost 下面加个context.xml文件么3.在conf下面的context.xml文件中,</Context>之前加入 <ResourceLink name="jdbc/Northwind" global="jdbc/Northwind" type="javax.sql.DataSourcer"/>
    这样做的错误还是一样啊
      

  2.   

    不是
    是加一个jasper.xml, 其中加一段 <context ></context>
      

  3.   

    那conf下面没有context。xml文件阿
      

  4.   

    不是 context.xml 
    是jasper.xml ,如果没有的话就新建一个
    在jasper.xml文件中包含:
    <context>
    ....
    ....
    ....
    ....
    </context>
      

  5.   

    如: jasper.xml中的内容
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/jasper" docBase="jasper" debug="1" reloadable="true" crossContext="true"></Context>
      

  6.   

    <name>factory</name>
          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
          </parameter>5.5已经不需要这个了只要把dbcp放在common/lib下就可以了删掉这段
      

  7.   

    如果datasource配置过于繁琐,实际上在部署安装的过程中没有很大的意义
    还不如自己写一个读取xml的文件,xml文件里保存好连接串呢
    各位以为如何