Jay Zhu
Jay Zhu

Reputation: 1672

Is there a container-neutral way of enabling directory listing?

I have a web app which contains some static contents. I'd like to make it browse-able. I test the web app in my local environment using Jetty and deploy it in production environment which uses Tomcat. Note that in Tomcat there are many other webapps been deployed and I do not want to interfere their settings.

It seems that I can do it by changing the settings of default servlet, for Tomcat:

   <servlet>
       <servlet-name>listing</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>

But it will cause problem when run it in Jetty environment since there is no org.apache.catalina.servlets.DefaultServlet exists.

So here comes the question: Is there a way that I can enable directory listing for both Jetty and Tomcat?

Upvotes: 2

Views: 81

Answers (1)

jesse mcconnell
jesse mcconnell

Reputation: 7182

Yep, don't use the default servlet of the container, create your own that does what you want and register it accordingly.

[edit] default servlets are a convenience, nothing more

Upvotes: 1

Related Questions