首页 > 技术文章 > 配置Tomcat直接显示目录结构和文件列表

zhangmingcheng 2017-07-05 15:57 原文

Tomcat是直接显示目录结构和文件列表,只是在配置里面给关闭了。 
关键在这里:\conf\web.xml 

这个文件有一段配置直接控制Tomcat是允许显示目录结构和文件列表。 

Java代码  收藏代码
  1. <servlet>  
  2.     <servlet-name>default</servlet-name>  
  3.     <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>  
  4.     <init-param>  
  5.         <param-name>debug</param-name>  
  6.         <param-value>0</param-value>  
  7.     </init-param>  
  8.     <init-param>  
  9.         <param-name>listings</param-name>  
  10.         <param-value>false</param-value>  
  11.     </init-param>  
  12.     <load-on-startup>1</load-on-startup>  
  13. </servlet>  

把listings选项改为true就可以了。 另外把<welcome-file>的配置去掉

例子



org.apache.catalina.servlets.DefaultServlet支持许多配置选项,在这个web.xml文件里面都有注释。 

Java代码  收藏代码
    1. <!-- The default servlet for all web applications, that serves static     -->  
    2.  <!-- resources.  It processes all requests that are not mapped to other   -->  
    3.  <!-- servlets with servlet mappings (defined either here or in your own   -->  
    4.  <!-- web.xml file.  This servlet supports the following initialization    -->  
    5.  <!-- parameters (default values are in square brackets):                  -->  
    6.  <!--                                                                      -->  
    7.  <!--   debug               Debugging detail level for messages logged     -->  
    8.  <!--                       by this servlet.  [0]                          -->  
    9.  <!--                                                                      -->  
    10.  <!--   fileEncoding        Encoding to be used to read static resources   -->  
    11.  <!--                       [platform default]                             -->  
    12.  <!--                                                                      -->  
    13.  <!--   input               Input buffer size (in bytes) when reading      -->  
    14.  <!--                       resources to be served.  [2048]                -->  
    15.  <!--                                                                      -->  
    16.  <!--   listings            Should directory listings be produced if there -->  
    17.  <!--                       is no welcome file in this directory?  [false] -->  
    18.  <!--                       WARNING: Listings for directories with many    -->  
    19.  <!--                       entries can be slow and may consume            -->  
    20.  <!--                       significant proportions of server resources.   -->  
    21.  <!--                                                                      -->  
    22.  <!--   output              Output buffer size (in bytes) when writing     -->  
    23.  <!--                       resources to be served.  [2048]                -->  
    24.  <!--                                                                      -->  
    25.  <!--   readonly            Is this context "read only", so HTTP           -->  
    26.  <!--                       commands like PUT and DELETE are               -->  
    27.  <!--                       rejected?  [true]                              -->  
    28.  <!--                                                                      -->  
    29.  <!--   readmeFile          File name to display with the directory        -->  
    30.  <!--                       contents. [null]                               -->  
    31.  <!--                                                                      -->  
    32.  <!--   sendfileSize        If the connector used supports sendfile, this  -->  
    33.  <!--                       represents the minimal file size in KB for     -->  
    34.  <!--                       which sendfile will be used. Use a negative    -->  
    35.  <!--                       value to always disable sendfile.  [48]        -->  
    36.  <!--                                                                      -->  
    37.  <!--   useAcceptRanges     Should the Accept-Ranges header be included    -->  
    38.  <!--                       in responses where appropriate? [true]         -->  
    39.  <!--                                                                      -->  
    40.  <!--  For directory listing customization. Checks localXsltFile, then     -->  
    41.  <!--  globalXsltFile, then defaults to original behavior.                 -->  
    42.  <!--                                                                      -->  
    43.  <!--   localXsltFile       Make directory listings an XML doc and         -->  
    44.  <!--                       pass the result to this style sheet residing   -->  
    45.  <!--                       in that directory. This overrides              -->  
    46.  <!--                        globalXsltFile[null]                          -->  
    47.  <!--                                                                      -->  
    48.  <!--   globalXsltFile      Site wide configuration version of             -->  
    49.  <!--                       localXsltFile This argument is expected        -->  
    50.  <!--                       to be a physical file. [null]                  -->  
    51.  <!--                                                                      -->  
    52.  <!--      

推荐阅读