试了这个方法,完全可行。
原文http://wso2.org/node/1096/print
Step 1 : Create a folder inside TOMCAT_HOME/webapps(eg: TOMCAT_HOME/webapps/my-files )Add some content(files,images) to this folder.Step 2 :Add folder 'WEB-INF' inside my-files folder.(eg: TOMCAT_HOME/webapps/my-files/WEB-INF )Step 3 :Add a web.xml file inside WEB-INF folder with following contents.(for tomcat-5.5.20)
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>default-myfiles</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>
<servlet-mapping>
<servlet-name>default-myfiles</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Step 4 :Start tomcat & navigate to http://localhost:PORT/my-files/.You will see the contents of the directory.Try changing the value of listing to 'false'. Step 5 :Check TOMCAT_HOME/conf/web.xml for more configuration options.(eg: welcome file, mime settings, url patterns)
可以看到目录下面的所有文件,但是只有txt文件能打开。其他ppt,doc文件都打不开。另外通过配置虚拟目录似乎也可行,可以这样可以显示硬盘上的任何一个目录,而不是局限于显示tomcat目录结构下的东西。