首先,将数据库的驱动包拷贝到[tomcat安装目录]\common\lib\目录下,如果没有数据库的驱动包可到网上下载,放到该目录下即可。
其次,在[tomcat安装目录]\conf\server.xml,添加数据库连接配置,如下所示:
<Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/> <GlobalNamingResources> <Environment name="simpleValue" type="java.lang.Integer" value="30"/> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="/report" docBase="report" reloadable="false"> <Resource name="mysql" auth="Container" type="javax.sql.DataSource" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf8" maxActive="20" /> </Context> </Host> </Engine> </Service> </Server>
tomcat5下,如果打了war包,那么最简单的办法就是把war拷贝到[tomcat安装目录]\webapps目录下,tomcat会自动解压缩,并发布应用。