tomcat的版本是5.5.16的 在本机(XP系统)上配置了下 没有问题 配置方式如下采用局部web应用配置:首先:在/conf/Catalina/localhost/下建立一个与自己web应用相同文件名的xml配置文件(wlk.xml)<?xml version="1.0" encoding="UTF-8" ?>
<Context path="/wlk" docBase="/wlk" debug="5" reloadable="true" crossContext="true">
<Resource driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/wireless" username="root"
password="123456" name="jdbc/mysql" type="javax.sql.DataSource" auth="Container"
maxActive="20" maxIdle="10" maxWait="5000" />
</Context>其次:配置/webapp/wlk/WEB-INF/下web.xml,在该文件的web-app></web-app>中添加如下内容
<resource-ref>
<description>DBConnection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>最后:通过下面的方式,获取connection
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mysql");
conn = ds.getConnection();
//conn.setAutoCommit(false);
return conn;上面的配置在本地机上测试,整个web应用运行起来完全没问题但是在服务器上进行相同的配置后(linux系统,tomcat版本也是5.5.16的)在浏览器里输入地址,提示The requested resource (/wlk/) is not available.
通常这个问题都是由于web.xml文件没配置对所导致的,但是相同的配置在个人机子上完全没问题,怎么到了服务器就不行了,是不是不同系统下的连接池配置也不同吗 请大家帮忙解决,谢谢了~!
<Context path="/wlk" docBase="/wlk" debug="5" reloadable="true" crossContext="true">
<Resource driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/wireless" username="root"
password="123456" name="jdbc/mysql" type="javax.sql.DataSource" auth="Container"
maxActive="20" maxIdle="10" maxWait="5000" />
</Context>其次:配置/webapp/wlk/WEB-INF/下web.xml,在该文件的web-app></web-app>中添加如下内容
<resource-ref>
<description>DBConnection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>最后:通过下面的方式,获取connection
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mysql");
conn = ds.getConnection();
//conn.setAutoCommit(false);
return conn;上面的配置在本地机上测试,整个web应用运行起来完全没问题但是在服务器上进行相同的配置后(linux系统,tomcat版本也是5.5.16的)在浏览器里输入地址,提示The requested resource (/wlk/) is not available.
通常这个问题都是由于web.xml文件没配置对所导致的,但是相同的配置在个人机子上完全没问题,怎么到了服务器就不行了,是不是不同系统下的连接池配置也不同吗 请大家帮忙解决,谢谢了~!
学习
<Context displayName="YTDS" docBase="eReport" path="/eReport" workDir="work\Catalina\localhost\eReport">
<Resource name="YTDS" type="javax.sql.DataSource"/>
<ResourceParams name="YTDS">
<parameter>
<name>url</name>
<value>jdbc:db2://127.0.0.1:50000/test</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.ibm.db2.jcc.DB2Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>test</value>
</parameter>
<parameter>
<name>password</name>
<value>test</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>500</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>100</value>
</parameter>
</ResourceParams>
</Context><res-ref-name>YTDS</res-ref-name>
然后用一下
???
localhost是指本机器的IP。 等同于127.0.0.1,配在服务器后 因该指定他的具体IP
放在$TOMCAT/common/lib下
java.lang.IllegalArgumentException: Document base /wlk does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:140)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3814)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3985)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:608)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1112)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)查看了日志 报出了上面的错误 wlk.xml中的 docBase="/wlk" 配置出了问题 这么配置不对吗 应该如何呢?
wlk.xml文件中
<Context path="/wlk" docBase="/wlk" debug="5" reloadable="true" crossContext="true"> 改为<Context>就好了,无需指定任何属性
希望对以后碰到相同问题的朋友会有帮助