【转帖】Tomcat服务器Server.xml的关键参数配置
说明:以下文字均以tomcat5.0.30为例进行。
1,配置tomcat服务器访问端口,只需配置Connector的port端口即可。Tomcat默认为8080,现修改port参数值为80。
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
<Connector port="80"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK"/>
2,配置tomcat支持URL中文参数,只需添加Connector的URIEncoding参数即可,默认情况下该参数未被配置。要支持URL参数支持中文,加上URIEncoding=”GBK”就行了(见1中附代码最后一行)。
3,配置新的webApp:找到host尾标记</Host>,插入新的context即可。
如:
(1)<Context path="" docBase="ROOT" debug="0"/>
若要支持数据库(以SQL Server为例),则为:
(2)<Context path="/xkb" docBase="F:\XKB6\webApp" debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/SqlServerDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SqlServerDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit.-->
<parameter>
<name>maxActive</name>
<value>50</value>
</parameter>
<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit.-->
<parameter>
<name>maxIdle</name>
<value>20</value>
</parameter>
<!-- Maximum time to wait for a dB connection to become available in ms, in this example 0.5 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->
<parameter>
<name>maxWait</name>
<value>500</value>
</parameter>
<!-- msSQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>wangnewton</value>
</parameter>
<!-- Class name for SQLServer2000 JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<!-- The JDBC connection url for connecting to your MS SQL Server dB.The autoReconnect=true argument to the url makes sure that the mm.Sql Server JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours.-->
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databaseName=XKBCourse</value>
<!--must use & not use & -->
</parameter>
</ResourceParams>
</Context>
1,配置tomcat服务器访问端口,只需配置Connector的port端口即可。Tomcat默认为8080,现修改port参数值为80。
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
<Connector port="80"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK"/>
2,配置tomcat支持URL中文参数,只需添加Connector的URIEncoding参数即可,默认情况下该参数未被配置。要支持URL参数支持中文,加上URIEncoding=”GBK”就行了(见1中附代码最后一行)。
3,配置新的webApp:找到host尾标记</Host>,插入新的context即可。
如:
(1)<Context path="" docBase="ROOT" debug="0"/>
若要支持数据库(以SQL Server为例),则为:
(2)<Context path="/xkb" docBase="F:\XKB6\webApp" debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/SqlServerDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SqlServerDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit.-->
<parameter>
<name>maxActive</name>
<value>50</value>
</parameter>
<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit.-->
<parameter>
<name>maxIdle</name>
<value>20</value>
</parameter>
<!-- Maximum time to wait for a dB connection to become available in ms, in this example 0.5 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -->
<parameter>
<name>maxWait</name>
<value>500</value>
</parameter>
<!-- msSQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>wangnewton</value>
</parameter>
<!-- Class name for SQLServer2000 JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<!-- The JDBC connection url for connecting to your MS SQL Server dB.The autoReconnect=true argument to the url makes sure that the mm.Sql Server JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours.-->
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databaseName=XKBCourse</value>
<!--must use & not use & -->
</parameter>
</ResourceParams>
</Context>