Tomcat是直接显示目录结构和文件列表,只是在配置里面给关闭了。
关键在这里:\conf\web.xml
这个文件有一段配置直接控制Tomcat是允许显示目录结构和文件列表。
Java代码
<servlet>
default</servlet-name>
class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
false</param-value>
</init-param>
1</load-on-startup>
</servlet>
把listings选项改为true就可以了。 另外把<welcome-file>的配置去掉
例子
org.apache.catalina.servlets.DefaultServlet支持许多配置选项,在这个web.xml文件里面都有注释。 Java代码
<!-- resources. It processes all requests that are not mapped to other -->
<!-- servlets with servlet mappings (defined either here or in your own -->
<!-- web.xml file. This servlet supports the following initialization -->
default values are in square brackets): -->
<!-- -->
for messages logged -->
this servlet. [0] -->
<!-- -->
static resources -->
default] -->
<!-- -->
<!-- input Input buffer size (in bytes) when reading -->
2048] -->
<!-- -->
if there -->
this directory? [false] -->
for directories with many -->
<!-- entries can be slow and may consume -->
<!-- significant proportions of server resources. -->
<!-- -->
<!-- output Output buffer size (in bytes) when writing -->
2048] -->
<!-- -->
this context "read only", so HTTP -->
<!-- commands like PUT and DELETE are -->
true] -->
<!-- -->
<!-- readmeFile File name to display with the directory -->
null] -->
<!-- -->
this -->
for -->
<!-- which sendfile will be used. Use a negative -->
48] -->
<!-- -->
<!-- useAcceptRanges Should the Accept-Ranges header be included -->
true] -->
<!-- -->
<!-- For directory listing customization. Checks localXsltFile, then -->
<!-- globalXsltFile, then defaults to original behavior. -->
<!-- -->
<!-- localXsltFile Make directory listings an XML doc and -->
this style sheet residing -->
<!-- in that directory. This overrides -->
null] -->
<!-- -->
<!-- globalXsltFile Site wide configuration version of -->
<!-- localXsltFile This argument is expected -->
null] -->
<!-- -->
<!--