按网上已经对tomcat目录下的conf文件的web.xml和context.xml进行了修改,配置好的了,可是启动或者jsp文件在运行的这两个文件自动复原了,之前的配置消失了,报这个错误

解决方案 »

  1.   

    把你的contex.xml放在tomcat下的conf\Catalina\localhost下面。
      

  2.   

    1. 把要配置数据库链接池所需要的JDBC Driver' jar拷贝至$CATALINA_HOME/lib.2. 在$CATALINA_HOME/conf/context.xml文件中的<Context>添加如下配置:
        <!-- the configuration of DBCP start -->
        <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
                   maxActive="100" maxIdle="30" maxWait="10000"
                   username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/league?autoReconnect=true"/>
        <!-- the configuration of DBCP end --> 注:此种方式配置的DataSource为全局的,任何项目只要部署在此Tomcat中的项目都能够使用
        此DataSource。   也可以在项目中配置局部的DataSource:
    在WebRoot/META-INF/目录下建立context.xml文件,文件中配置如下:<?xml version='1.0' encoding='utf-8'?>
    <Context>
        <!-- the configuration of DBCP start -->
        <Resource name="jdbc/MySQLDB" auth="Container" type="javax.sql.DataSource"
                   maxActive="100" maxIdle="30" maxWait="10000"
                   username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/league?autoReconnect=true"/>
        <!-- the configuration of DBCP end -->
    </Context>
    3. 测试代码如下: Context context = new InitialContext();
    DataSource dataSource = (DataSource)context.lookup("java:/comp/env/jdbc/MySQLDB");
      

  3.   

    请问这里的name="jdbc/MySQLDB" mysqlDB指的是什么,有的说是数据库名,有的说是实际地址
      

  4.   

    固定的
    url="jdbc:mysql://localhost:3306/数据库名?autoReconnect=true