日期:2014-05-16 浏览次数:20900 次
<?xml version="1.0" encoding="UTF-8"?>  
<Context path="/studentproject" docBase="studentproject"    
    debug="5" crossContext="true" reloadable="true"    
    cachingAllowed="true" cacheMaxSize="20480"    
    cacheTTL="10000">    
<WatchedResource>WEB-INF/web.xml</WatchedResource>  
<Resource    
  
name="jdbc/test"    
auth="Container"  
type="javax.sql.DataSource"  
driverClassName="com.mysql.jdbc.Driver"  
url="jdbc:mysql://localhost:3306/bbs?autoReconnect=true"  
username="root"  
password="root"  
maxActive="20"  
maxIdle="10"  
maxWait="-1" />  
  
</Context>  <?xml version="1.0" encoding="UTF-8"?>
<Context path="/studentproject" docBase="studentproject" 
    debug="5" crossContext="true" reloadable="true" 
    cachingAllowed="true" cacheMaxSize="20480" 
    cacheTTL="10000"> 
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource 
name="jdbc/test" 
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bbs?autoReconnect=true"
username="root"
password="root"
maxActive="20"
maxIdle="10"
maxWait="-1" />
</Context><?xml version="1.0" encoding="UTF-8"?>  
<web-app version="2.5"    
 xmlns="http://java.sun.com/xml/ns/javaee"    
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
    
<resource-ref>      
<description>DB Connections</description>  
<res-ref-name>jdbc/test</res-ref-name>  
<res-type>javax.sql.DataSource</res-type>  
<res-auth>Container</res-auth>  
</resource-ref>    
  
</web-app>  
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
 xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
<resource-ref>   
<description>DB Connections</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref> 
</web-app><%@ page language="java"  pageEncoding="UTF-8"%>    
<%@page contentType="text/html; charset=UTF-8"%>    
<%@page import="java.sql.*" %>    
<%@page import="javax.naming.*" %>    
<%@page import="javax.sql.DataSource" %>    
<head>    
<title>Tomcat6.0 JNDI 测试!</title>   
</head>   
     
  <body>    
    This is my JSP page. <br>    
    JNDI配置测试开始 ... <br>    
<%    
try {    
 //初始化 Context 上下文对象