可以用http://localhost:8080/admin来配置,这里先不说这个(因为先前编辑了半天结果没发表成功,估计是用了n多图片的关系)
现在在context名为quickstart配置数据源 ,目录为%tomcat_home/webapps/quickstart,quickstart下新建目录META-INF,META-INF下面新建context.xml,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<Context
reloadable="true">
<Resource
auth="Container"
description="mysql Connection"
name="jdbc/quickstart"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
password="hib"
maxIdle="2"
maxWait="5000"
username="hib"
url="jdbc:mysql://127.0.0.1:3306/quickstart?useUnicode=true&characterEncoding=GB2312"
maxActive="4"/>
<WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
<WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
<WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
</Context>
”<WatchedResource>“是我用admin新建context自动产生quickstart.xml时自动添加的。
quickstart下新建目录WEB-INF,在WEB-INF下新建web.xml,内容如下:
<?xml version="1.0" encoding="GB2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>quickstart实验</display-name>
<description>quickstart实验</description>
<!--引用资源说明 引用资源的JNDI名 引用资源的类名 管理者(Container)-->
<resource-ref>
<description>mysql Connection</description>
<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<!-- default page
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list> -->
</web-app>
当然千万别忘了下载mysql-connector-java-5.0.0-beta-bin.jar,或者其他的版本也可以啊