将下列代码放到tomcat的server.xml文件中的<host></host>之间
<Context path=”/huaxuntong” reloadable=”true” docBase=”d:/programe/java/huaxuntong/web” debug=”0″>
<Logger className=”org.apache.catalina.logger.FileLogger”
prefix=”localhost_test_log.” suffix=”.txt” timestamp=”true”/>
<Resource name=”jdbc/huaxuntongdb” auth=”Container” type=”javax.sql.DataSource”
factory=”org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory”
username=”root”
password=”"
driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost:3306/huaxuntongdb?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8″
maxWait=”1000″ removeAbandoned=”true”
maxActive=”100″ maxIdle=”30″
removeAbandonedTimeout=”60″ logAbandoned=”true”/>
</Context>
maxWait最大等待秒钟数,这里取值-1,表示无限等待,直到超时为止,也可以取值9000,即表示9秒后超时。
maxIdle是最大的空闲连接数,是一些与数据库的连接始终是保持着的,当你的应用程序要访问数据库的时候就可以优先使用这些连接,以提高速度,如果这 些连接数不够的话才会重新建立一些连接, 这里取值30个,表示即使没有连接请求时,依然可以保持30空闲的连接,而不被清除,随时处于待命状态。
在已发布项目的WEB-INF目录下放置一个web.xml 内容如下:
<!DOCTYPE web-app
PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
<web-app>
<display-name>demo</display-name>
<description> demo </description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/demo</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>