tomcat6 中context配置,使用tomcat 数据源

来源:互联网 发布:菜鸟网络盈利模式 编辑:程序博客网 时间:2024/05/16 18:08

如需在tomcat中加入一个web应用,而应用的目录又不在%tomcat%/webApp/下的时候,可以通过配置context来实现。例如应用名为sport。则需在%tomcat%/conf/Catalina/localhost 下建立一个sport.xml的文件,在文件中

<Context path="/sport" docBase="E:/sport/webRoot" debug="0" reloadable="true" crossContext="true"></Context>

则此时就可以用http://localhost:8080/sport来访问这个应用了。

 

如果想让这个应用为根目录,即打开http://localhost:8080即可访问。则需将sport.xml改为ROOT.xml

而相应的内容改为

 

<Context path="" docBase="E:/sport/webRoot" debug="0" reloadable="true" crossContext="true"></Context>

 

在tomcat6中的数据源的配置也可以不用在server.xml中配置也可以在刚才我们建的xml中配置。例如

 

<Context path="/sport" docBase="E:/sport/webRoot" debug="0" reloadable="true" crossContext="true">
<Resource 
    name="jdbc/sportds"
    auth="Container"
    type="javax.sql.DataSource" 
    driverClassName="com.mysql.jdbc.Driver"
 maxIdle="20"
 maxWait="5000" 
    username="root"
 password=""
 url="jdbc:mysql://localhost:3306/sport?useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=true" 
    maxActive="100"
    removeAbandoned="true"
    removeAbandonedTimeout="60"
    logAbandoned="true"
/>
</Context>

 

然后在web.xml 中在web-app之间加入

 

<resource-ref>
       <res-ref-name>jdbc/sportds</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

 

就可以使用tomcat数据源了。

0 0
原创粉丝点击