tomcat的Context配置
http://www.diybl.com/course/4_webprogram/jsp/jsp_js/200869/123916.html
tomcat的Context配置
今天终于搞定Tomcat的Context了,conf/Context.xml是Tomcat公用的环境配置;
若在Server.xml中增加<Context path="/test" docBase="D:\test" debug="0" reloadable="false"/>的话,
则myApp/META-INF/Context.xml就没用了(被server.xml中的Context替代),
Jndi 数据源或其他资源可直接定在里面,如:
- <Context path="/frame" docBase="C:\Java\jboss-4.0.1sp1\server\default\deploy\webroot.war" debug="0" reloadable="false">
- <Resource name="UserTransaction"
- auth="Container"
- type="javax.transaction.UserTransaction"
- factory="org.objectweb.jotm.UserTransactionFactory"
- jotm.timeout="60" />
- <Resource name="sharkdb"
- type="javax.sql.DataSource"
- password="helloworld"
- driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
- maxIdle="2"
- maxWait="5000"
- username="sa"
- url="jdbc:microsoft:sqlserver://192.168.0.193:1433;DatabaseName=test_cyber3;SelectMethod=cursor"
- maxActive="4"/>
- <Resource name="cyberwaydb"
- type="javax.sql.DataSource"
- password="helloworld"
- driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
- maxIdle="2"
- maxWait="5000"
- username="sa"
- url="jdbc:microsoft:sqlserver://192.168.0.193:1433;DatabaseName=test_cyber3"
- maxActive="4"/>
- </Context>
;若在<GlobalNamingResources>中增加的JNDI或其他的,在App中需引用,才能使用,以下两种引用方式:
A:在WEB-INF/web.xml 中配置如下:
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/TestDB</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
B:在yoursApp\META-INF\context.xml,
如下:
- <?xml version='1.0' encoding='utf-8'?>
- <Context path="/yoursApp"
- docBase="yoursApp" debug="5"
- reloadable="true"
- crossContext="true">
- <ResourceLink name="mysqlDBConPool"
- global="mysqlDBConPool"
- type="javax.sql.DataSource"/>
- </Context>