3 Replies Latest reply on Mar 31, 2003 4:14 AM by luwasoft

    How to disable directory listings with Tomcat and Struts

    mash1

      Hi,

      I would like to know how to disable directory listings in Tomcat, using the jboss-3.0.3_tomcat-4.1.12 bundle.

      I have found solutions on the Tomcat list for standalone Tomcat, but nothing for JBoss/Tomcat. The only servlet in my application is the Struts 1.1 ActionServlet. I can't find anything on the Struts list about special init params that may disable directory listings, either.

      I know I could simply place an index.jsp in each directory that redirects out, but that is a last resort.

      Thanks in advance,
      Mash

        • 1. Re: How to disable directory listings with Tomcat and Struts
          terry

          Mash,

          Try editing the web.xml file located in the

          $JBOSS_HOME/tomcat-4.1.x/conf

          directory. Within the definition, change:

          <init-param>
          <param-name>listings</param-name>
          <param-value>true</param-value>
          </init-param>

          to

          <init-param>
          <param-name>listings</param-name>
          <param-value>false</param-value>
          </init-param>

          This worked for me but I am not using Struts so I'm not sure if it will work for you.

          Terry

          • 2. Re: How to disable directory listings with Tomcat and Struts
            mash1

            Hi Terry,

            No, I tried that already and it doesn't work.

            Cheers,
            Mash

            • 3. Re: How to disable directory listings with Tomcat and Struts
              luwasoft

              Hi Mash,

              thanks for making me aware of this issue :-)

              I found a hack to solve your (and my newly discovered) issue:

              In your Web-App you should add to your web.xml a modified default servlet (if you use the ant build procedure supposed by JBoss the filename in your source tree the file is src\etc\WEB-INF\web-client.xml).

              Even if you think it would be the last option, adding a index.jsp to any directory and redirecting to a preferred destination looks to me a much cleaner solution. By doing what you want (and what i found, tested and post here) you get a result that is (from the webdesing point of view) really dirty: you show a buildt in tomcat error (! buh !). Of course you could make your own errorpage...
              What i suppose is to redefine the default servlet. JBoss-tomcat seems to define a servlet under the name "default", so i used just another name to prevent deployment exceptions.
              If one of the JBoss insiders could explain how one changes the JBOss defines "default" servlet definition i would be glad to here, in between my suggestion should solve your problem...

              Just add the fillowing lines to web.xml:
              <!-- to the servlet definitions: -->

              <servlet-name>myDefault</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>false</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>

              <!-- later to the servlet mappings: -->
              <servlet-mapping>
              <servlet-name>myDefault</servlet-name>
              <url-pattern>/</url-pattern>
              </servlet-mapping>

              Thats it!
              Hope this help.