How to enable directory listing in tomcat

试了这个方法,完全可行。

原文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目录结构下的东西。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值