tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [TC4] Disabling (Was: JSP pages, Now: dir. listings) in one context only
Date Tue, 29 Jan 2002 15:52:18 GMT


On Tue, 29 Jan 2002, chris brown wrote:

> Date: Tue, 29 Jan 2002 16:40:54 +0100
> From: chris brown <dev@reflexe.fr>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> Subject: Re: [TC4] Disabling (Was: JSP pages,
>      Now: dir. listings)  in one context only
>
> Thanks Craig,
>
> I posted a similar question recently asking whether it was possible to have
> different settings for the "default" servlet (per-context settings).  For
> example, in some contexts, I'd like to see directory listings, in others,
> I'd prefer not to.
>

That's a slightly different kettle of fish.  Out of the box, the only way
to do this locally to a webapp is to ensure that you have a static
resource that matches one of the welcome file patterns in every directory.

> I tried overriding the default servlet, but this always threw
> ServletExceptions in TC4.0.1 (didn't like multiple servlets sharing the same
> name between global web.xml and context-specific web.xml, but always seemed
> to resort to global default servlet if I used a different <servlet-name> for
> the default servlet in the context-specific web.xml).
>
> Obviously I could write a directory-listing servlet myself if I disabled the
> directory listing
> feature globally, but I'd have problems with other static resources.  I
> don't really understand how conflicting url mappings are handled between
> global and context configs either...
>

One strategy that might work would be along these lines:

* Override the default servlet with one of your own,
  mapping to the "/" URL pattern.

* In your override servlet, see if there really is a static
  resource at the requested path by calling
  ServletContext.getResourceAsStream().

* If there is such a file, get a named dispatcher for the
  "default" servlet (since there's no path mapped to this
  servlet, that's the only way that will work) and do a
  rd.forward() call to it.

* If there is not such a file, figure out if this request is
  for a "directory" or not.  If so, decide if this webapp should
  display listings or not.  If so, forward to the default
  servlet as above; otherwise do something else.

But it's a lot of work ... it's probably simpler just to make sure you
have a welcome file (by default, index.html or index.jsp) in every
directory, and you'll never see a directory listing.


> Thanks
> Chris B
>

Craig


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message