比如說
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="20"
maxIdel="10"
maxWait="1000"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mldn">
</Resource>
</Context>
將上面文件放在web目錄的meta-inf下面,還有妳的測試代碼要在同壹個web容器下運行啊,不要隨便寫個main方法就測試,那是在不同的jvm下,怎麽可能獲取到jndi對象呢,
妳在問問Google老師,應該能夠解決,還有在tomcat下的lib下放置相關jar包,比如數據源,dbcp那個,還有驅動