Tomcat 服务器server.xml的关键参数配置

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>

tomcat5.5.x 配置记录。

1.下载:
http://www.eu.apache.org/dist/jakarta/tomcat-5/
http://www.apache.org/dist/jakarta/tomcat-5/v5.5.x/bin/jakarta-tomcat-5.5.x-admin.zip
http://www.apache.org/dist/jakarta/tomcat-5/v5.5.x/bin/jakarta-tomcat-5.5.x-compat.zip
http://www.apache.org/dist/jakarta/tomcat-5/v5.5.x/bin/jakarta-tomcat-5.5.x.zip
http://www.apache.org/dist/jakarta/tomcat-5/v5.5.x/bin/jakarta-tomcat-5.5.x-deployer.zip
把jakarta-tomcat-5.5.x.zip
和jakarta-tomcat-5.5.x-compat.zip
和jakarta-tomcat-5.5.x-admin.zip
(Tomcat 默认是没有内置admin模块了
Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it. )
都解压到同一个目录下面。比如:D:/jakarta-tomcat-5.5.x/
(如果使用jdk1.4,才需要compat.zip用jdk1.5就可以免了这个。)

2.修改jakarta-tomcat-5.5.x/conf/tomcat-users.xml.
添加管理员账号lizongbo,密码为lizongbopass.
新xml如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="lizongbo" password="lizongbopass" roles="admin,manager"/>
</tomcat-users>

3.修改jakarta-tomcat-5.5.x/conf/server.xml来解决编码问题。
(给Connector 添加URIEncoding参数,参考http://blog.csdn.net/darkxie/archive/2004/10/25/TOMCATAPP.aspx)
(可以设置成GB18030)
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="200"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"
compression="on" compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"/>

<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" URIEncoding="GBK"/>

4.启用支持gzip压缩.
(http://www.linuxaid.com.cn/forum/showdoc.jsp?l=1&i=81169)
添加下列属性
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"

5.设置虚拟主机。
在jakarta-tomcat-5.5.x/下建立文件夹vhost/www.mydomain.com。
然后修改jakarta-tomcat-5.5.x/conf/server.xml

<Engine defaultHost="localhost" name="Catalina">
<Host appBase="vhost/www.mydomain.com" name="www.mydomain.com">
</Host>
<Host appBase="webapps" name="localhost">
</Host>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>

6.添加数据库驱动,更新mail.jar和actiovation.jar
复制mysql-connector-java-3.0.16-ga-bin.jar,pg74.215.jdbc3.jar到 jakarta-tomcat-5.5.x/common/lib/
还有javamail 1.3.2的mail.jar,jaf-1_0_2的 activation.jar
msSQl 2000 JDBC sp3,msbase.jar,msutil,jar,mssqlserver.jar

7.配置SSL
参考 http://jakarta.apache.org/tomcat/tomcat-5.5-doc/ssl-howto.html
D:/j2sdk1.4.2_06/bin>%JAVA_HOME%/bin/keytool -genkey -alias tomcat -keyalg RSA
输入keystore密码: lizongbossl
您的名字与姓氏是什么?
[tomcat5.5.x]: tomcat5.5.x
您的组织单位名称是什么?
[jakarta]: jakarta
您的组织名称是什么?
[apache]: apache
您所在的城市或区域名称是什么?
[hzcity]: hzcity
您所在的州或省份名称是什么?
[gdp]: gdp
该单位的两字母国家代码是什么
[CN]: CN
CN=tomcat5.5.x, OU=jakarta, O=apache, L=hzcity, ST=gdp, C=CN 正确吗?
[否]: y

输入<tomcat>的主密码
(如果和 keystore 密码相同,按回车):

(必须密码一致,因此直接回车)
然后再把userhome(例如:C:/Documents and Settings/lizongbo/)下的.keystore复制到
tomcat的conf/目录下。
(例如:D:/jakarta-tomcat-5.5.x/conf/.keystore )
配置jakarta-tomcat-5.5.x/conf/server.xml
加上
<Connector port="8443"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/.keystore"
keystorePass="lizongbossl"> <!--与先前设置的密码一致-->
</Connector>
8.禁止文件目录列表,
修改jakarta-tomcat-5.5.x/conf/web.xml,把listing设置为false

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

9.指定了自己的javaEncoding
(参考 http://gceclub.sun.com.cn/staticcontent/html/sunone/app7/app7-dg-webapp/ch6/ch6-4.html )

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>javaEncoding</param-name>
<param-value>GB18030</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
10.添加rar,iso等的mime-type映射
避免在浏览器里直接打开。
<mime-mapping>
<extension>mht</extension>
<mime-type>text/x-mht</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rar</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>iso</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ape</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>rmvb</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
10.1对html静态页面设置编码
<!-- 修改下面两行以支持静态超文本的自动编码
-->
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html;charset=gb2312</mime-type>
</mime-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html;charset=gb2312</mime-type>
</mime-mapping>
</web-app>

11.添加welcome-file-list,并调整顺序。
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

Tomcat中文编码问题解决方案(简)

liyonghai 04/08/30

编码问题的根源可参考http://www-900.ibm.com/developerWorks/cn/java/java_chinese/index.shtml

Tomcat 4.x解决方法:
获取中文:request.setCharacterEncoding("gb2312");
输出中文:<%@ page contentType="text/html;charset=gb2312" %>,必要时需要转码

Tomcat 5.x解决方法:
获取中文:
提交表单时
1)post:request.setCharacterEncoding("gb2312");
2)get:修改server.xml,在Connector中加入URIEncoding="gb2312"
如: <Connector port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="gb2312" />
或者使用useBodyEncodingForURI,使tomcat 5.x兼容tomcat 4.x
输出中文:<%@ page contentType="text/html;charset=gb2312" %>,必要时需要转码

附:Tomcat 5.x与Tomcat 4.x在解析提交表单时发生了变化,Tomcat 4.x无论是post还是get,都使用
相同的编码,而Tomcat 5.x 却把get方法单独了出来.具体可查看tomcat的source code.

get方式的处理比较好,对于post方式建议用配置过滤器的方式来解决,因为这样,配置一个地方整个系统都不用操心了。

简单说明:
web.xml
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>SetCharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
/************************/

SetCharacterEncodingFilter.java
--------------------------------------------
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;

/**
* Example filter that sets the character encoding to be used in parsing the
* incoming request
*/
public class SetCharacterEncodingFilter implements Filter {

/**
* Take this filter out of service.
*/
public void destroy() {
}
/**
* select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)throws IOException, ServletException {

request.setCharacterEncoding("GBK");

// 传递控制到下一个过滤器
chain.doFilter(request, response);
}

public void init(FilterConfig filterConfig) throws ServletException {
}
}
也可以把编码做为参数传递进去。

12.如果你的webapp需要只能够进行https方式访问,那么在webapp的web.xml里加上:
<security-constraint>
<web-resource-collection>
<web-resource-name>must https</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
参考:http://jakarta.apache.org/tomcat/faq/security.html#https
http://marc.theaimsgroup.com/?l=tomcat-user&m=104951559722619&w=2

13.修改远程关闭服务器的命令。
server.xml默认有下面一行:
<Server port="8005" shutdown="SHUTDOWN">
这样允许任何人只要telnet到服务器的8005端口,输入"SHUTDOWN",然后回车,服务器立即就被关掉了。
从安全的角度上考虑,我们需要把这个shutdown指令改成一个别人不容易猜测的字符串。
例如修改如下:
<Server port="8006" shutdown="lizongbo">,这样就只有在telnet到8005,并且输入"lizongbo"才能够关闭Tomcat.
注意:这个修改不影响shutdown.bat的执行。运行shutdown.bat一样可以关闭服务器。
参考:http://jakarta.apache.org/tomcat/faq/security.html#8005

以下皆可以参考:http://www.cnjsp.org/document/user/tuman/valve.html

14.配置http访问日志。Tomcat自带的能够记录的http访问日志已经很详细了
取消下面这段的注释:

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>

然后修改为:
<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="combined" resolveHosts="false" fileDateFormat="yyyy-MM-dd.HH"/>

pattern="combined" 记录的日志内容更详细,fileDateFormat="yyyy-MM-dd.HH",会让日志文件按小时进行滚卷,
比默认的按天滚卷要好些,尤其是访问量大的网站,可以考虑写成fileDateFormat="yyyy-MM-dd.HH.mm",就会是每分钟一个日志文件了。
而且可以分别按Engine, Host, or Context,来记录自己的日志
详情参考:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/valve.html
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/logger.html
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/host.html#Access%20Logs
而且还可以配合awstats来进行日志统计分析: http://www.chedong.com/tech/awstats.html http://blog.csdn.net/lizongbo/archive/2005/02/18/291929.aspx

15.限制ip,限制主机访问等。
如果想禁止指定的ip或者主机名来拒绝某些机器访问,或者指定某些机器来访问。
也支持分别按Engine, Host, or Context,进行以下配置:
<Context path="/examples" ...> ...
<Valve className="org.apache.catalina.valves.RemoteHostValve"
allow="*.mycompany.com,www.yourcompany.com"/>
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
deny="192.168.1.*"/>
</Context>
参考:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html

16.发布webapp到网站根目录
1。直接复制到ROOT目录下。
2.因为无法创建无名字的xml文件,并且在xml文件里指定path也是无效的(tomcat靠文件名字来判断的),
因此必须在server.xml里写下面一段:
<Context docBase="${catalina.home}/vhost/www.lizongbo.com" path="/"
privileged="true" antiResourceLocking="false" antiJARLocking="false">
<Manager className="org.apache.catalina.session.StandardManager" algorithm="SHA-512" sessionIdLength="40">
<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
directory="logs" prefix="localhost_mytest_access_log." suffix=".txt"
pattern="combined" resolveHosts="true" fileDateFormat="yyyy-MM-dd.HH"/>

</Context>
而且必须把ROOT目录删除掉,否则Tomcat还是优先部署ROOT目录为"/"。

17.在重新启动Tomcat的webapp的时候,禁止把session写入文件。
修改conf/web.xml
取消注释:
<!---->
<Manager pathname="" />

18.增强SessiionID的生成算法和长度。

<Manager className="org.apache.catalina.session.StandardManager" algorithm="SHA-512" sessionIdLength="40">
</Manager>

(Tomcat默认算法是MD5,默认长度是16位。)


//------------------------------------------------------------------------------------------------------------------------------------------

 

http://blog.csdn.net/dakuen/
 
 
1.下载 ::URL:: http://www.eu.apache.org/dist/jakarta/tomcat-5/
这里注意,在jakarta-tomcat-5.0.28.exe以前是有默认的admin模块,在jakarta-tomcat-5.5.9.exe则没有安装默认的admin模块,这时 ::URL:: http://127.0.0.1:8080/admin打开时则会出现
Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it. 
因此我们现在需要下载"admin"package 包
把jakarta-tomcat-5.5.x.zip  与   jakarta-tomcat-5.5.x-compat.zip  与  jakarta-tomcat-5.5.x-admin.zip
三个文件解压在同一个目录中
(如果使用jdk1.4,才需要compat.zip用jdk1.5就可以免了这个。) 




2.修改jakarta-tomcat-5.5.x/conf/tomcat-users.xml.
添加管理员账号lizongbo,密码为lizongbopass.
新xml如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="lizongbo" password="lizongbopass" roles="admin,manager"/>
</tomcat-users>


有时在%CATALINA_HOME%/server/webapps/admin/WEB-INF/web.xml里面也要做些修改


<!-- Security is active on entire directory -->
  <security-constraint>
    <display-name>Tomcat Server Configuration Security Constraint</display-name>
    <web-resource-collection>
      <web-resource-name>Protected Area</web-resource-name>
      <!-- Define the context-relative URL(s) to be protected -->
      <url-pattern>*.jsp</url-pattern>
      <url-pattern>*.do</url-pattern>
      <url-pattern>*.html</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <!-- Anyone with one of the listed roles may access this area -->
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Login configuration uses form-based authentication -->
  <login-config>
    <auth-method>FORM</auth-method>
    <realm-name>Tomcat Server Configuration Form-Based Authentication Area</realm-name>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
  </login-config>

  <!-- Security roles referenced by this web application -->
  <security-role>
    <description>
      The role that is required to log in to the Administration Application
    </description>
    <role-name>admin</role-name>
  </security-role>
无论是 Authetication ( 身份验证   还是 Authorization ( 权限管控   都只有设置相关的 admin ROLE, 当你想要新增或修改相关的 AA, 就必须修改这一个文件, 来符合你的环境.
3.修改jakarta-tomcat-5.5.x/conf/server.xml来解决编码问题。
(给Connector 添加URIEncoding参数,参考 ::URL:: http://blog.csdn.net/darkxie/archive/2004/10/25/TOMCATAPP.aspx)
(可以设置成GB18030)
    <Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="200"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"
               compression="on" compressionMinSize="2048" 
      noCompressionUserAgents="gozilla, traviata" 
      compressableMimeType="text/html,text/xml"/>
 
    <Connector port="8009" 
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" URIEncoding="GBK"/>
 

4.启用支持gzip压缩.
( ::URL:: http://www.linuxaid.com.cn/forum/showdoc.jsp?l=1&i=81169)
添加下列属性
 compression="on" 
      compressionMinSize="2048" 
      noCompressionUserAgents="gozilla, traviata" 
      compressableMimeType="text/html,text/xml"
 
5.设置虚拟主机。
在jakarta-tomcat-5.5.x/下建立文件夹vhost/www.mydomain.com。
然后修改jakarta-tomcat-5.5.x/conf/server.xml
 
<Engine defaultHost="localhost" name="Catalina">
      <Host appBase="vhost/www.mydomain.com" name=" ::URL:: http://www.mydomain.com/">
      </Host>
      <Host appBase="webapps" name="localhost">
      </Host>
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
    </Engine>
 
6.添加数据库驱动,更新mail.jar和actiovation.jar
复制mysql-connector-java-3.0.16-ga-bin.jar,pg74.215.jdbc3.jar到 jakarta-tomcat-5.5.x/common/lib/
还有javamail 1.3.2的mail.jar,jaf-1_0_2的 activation.jar
msSQl 2000 JDBC sp3,msbase.jar,msutil,jar,mssqlserver.jar
 
 
7.配置SSL
参考  ::URL:: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/ssl-howto.html
D:/j2sdk1.4.2_06/bin>%JAVA_HOME%/bin/keytool -genkey -alias tomcat -keyalg RSA
输入keystore密码:  lizongbossl
您的名字与姓氏是什么?
  [tomcat5.5.x]:  tomcat5.5.x
您的组织单位名称是什么?
  [jakarta]:  jakarta
您的组织名称是什么?
  [apache]:  apache
您所在的城市或区域名称是什么?
  [hzcity]:  hzcity
您所在的州或省份名称是什么?
  [gdp]:  gdp
该单位的两字母国家代码是什么
  [CN]:  CN
CN=tomcat5.5.x, OU=jakarta, O=apache, L=hzcity, ST=gdp, C=CN 正确吗?
  [否]:  y
 
输入<tomcat>的主密码
        (如果和 keystore 密码相同,按回车):

(必须密码一致,因此直接回车)
然后再把userhome(例如:C:/Documents and Settings/lizongbo/)下的.keystore复制到
tomcat的conf/目录下。
 (例如:D:/jakarta-tomcat-5.5.x/conf/.keystore 
配置jakarta-tomcat-5.5.x/conf/server.xml
加上
    <Connector port="8443" 
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
           keystoreFile="conf/.keystore" 
           keystorePass="lizongbossl"> <!--与先前设置的密码一致-->
    </Connector>
8.禁止文件目录列表,
修改jakarta-tomcat-5.5.x/conf/web.xml,把listing设置为false
 
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
 9.指定了自己的javaEncoding
(参考  ::URL:: http://gceclub.sun.com.cn/staticcontent/html/sunone/app7/app7-dg-webapp/ch6/ch6-4.html 

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
                <init-param>
            <param-name>javaEncoding</param-name>
            <param-value>GB18030</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>
 10.添加rar,iso等的mime-type映射 
避免在浏览器里直接打开。
<mime-mapping>
<extension>mht</extension>
<mime-type>text/x-mht</mime-type>
</mime-mapping>
<mime-mapping>
        <extension>rar</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>iso</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>ape</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>rmvb</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>ico</extension>
        <mime-type>image/x-icon</mime-type>
    </mime-mapping>
10.1对html静态页面设置编码
<!--  修改下面两行以支持静态超文本的自动编码 
  --> 
 <mime-mapping>
  <extension>htm</extension> 
  <mime-type>text/html;charset=gb2312</mime-type> 
  </mime-mapping>
 <mime-mapping>
  <extension>html</extension> 
  <mime-type>text/html;charset=gb2312</mime-type> 
  </mime-mapping>
  </web-app>
 
11.添加welcome-file-list,并调整顺序。
 <welcome-file-list>    
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list> 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值