tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Milt Epstein <mepst...@uiuc.edu>
Subject RE: URL patterns + directory listings
Date Fri, 20 Sep 2002 15:28:54 GMT
On Fri, 20 Sep 2002, adi wrote:

> Thanks,
> I will try to explain what I am trying to do.
>
> My project directory structure is something like this:
>
> MyContext/admin
> MyContext/admin/config
> MyContext/userdata
> MyContext/userdata/user1
> MyContext/userdata/user2
>
> ... I want to enable listing on admin and its subs
> and disable listing on MyContext/
> 			     MyContext/userdata

I don't know if you can do this using DefaultServlet and the listings
init-param.  At least, I can't think of a way to do it right now (but
I didn't get enough sleep last night :-).  One way you *can* do it is
by putting/not putting appropriate index.html (or the welcome-file of
your choice) files in those directories.

Oh wait, here's an idea.  Define two instances of DefaultServlet, one
with listings true and one with listings false.  Then set up
appropriate url-pattern's so that the right one is called for the
right directories.  No, wait, then you run into the same problem with
virtual directories in url-pattern's hiding the real subdirectories.

Maybe you can set up something with a servlet that intercepts all
these requests and dispatches them appropriately, deciding whether to
allow listings or not per request (or passing it to the appropriate
DefaultServlet).

One thing though, do you have other dynamic content in this context?
Other servlets and/or JSPs?  Because if you do, you want to be careful
to not over-generalize the url-pattern's such that you can't call
those servlets/JSPs.  That is, you might end up such that all URLs end
up going to DefaultServlet.  (But if you don't have other dynamic
content, I don't understand why you just don't use Apache to do all
this, it's got very clear mechanisms for controlling directory listings.)


> I set the listings property on default servlet to false ( in
> tomcat/conf/web.xml )
>
> and now i want all patterns with admin in it to show listings.
> What I tried to do is to create another default servlet, this time
> with listings=true and to map it to all patterns with admin/*
> I added this mapping in MyContext/WEB-INF/web.xml.
> ...but then I face this strange behaviour I described in the first
> mail on this thread.

Right.  But I don't think it's strange at all, I think it's the right
behavior for what you have set up.  That is, it'sdoing what you told
it to do, which unfortunately wasn't what you wanted it to do :-).


> Even if this is not a good way to allow listings on certain directories
> I realy want to understand why I get the listing for
> http://localhost/MyContext/
> when I point my browser to http://localhost/MyContext/admin/

Again, directories in URLs may be virtual directories that bear no
correspondence to real directories in the file system.  This is a
basic property of web servers, it allows you to organize your web
content/URL-space differently than the way your file system is
organized.  It allows you to map any URL to any file/resource on your
file system.

When you specify the servlet-mapping:

  <servlet-mapping>
    <servlet-name>MyDefaultServlet</servlet-name>
    <url-pattern>/admin/*</url-pattern>
  </servlet-mapping>

you're saying that any URL (after the server name and context path)
that begins with "/admin/*" should be passed to MyDefaultServlet.
It's got nothing to do with any directory that may or may not exist in
our file system.  And when you do this, you're effectively hiding the
admin subdirectory such that you need to specify it twice in the URL
to get to it.  Think of it another way, if instead you had:

  <servlet-mapping>
    <servlet-name>MyDefaultServlet</servlet-name>
    <url-pattern>/blah/*</url-pattern>
  </servlet-mapping>

then http://localhost/MyContext/blah/ would likewise end up being
passed to MyDefaultServlet.  Like I said before, the fact that you had
admin in your url-pattern and it's also the name of a subdirectory in
your context, is really just an unfortunate, confusing coincidence
(well, really, it's an indication of confusion on your part).


> -----Original Message-----
> From: Milt Epstein [mailto:mepstein@uiuc.edu]
> Sent: Friday, September 20, 2002 2:53 PM
> To: Tomcat Users List
> Subject: Re: URL patterns + directory listings
>
>
> On Fri, 20 Sep 2002, adi wrote:
>
> > Hello,
> >
> > I encountered a very strange problem with servlet mappings.
> >
> >
> > I have the following entry in my web.xml file :
> >
> > <servlet>
> >     <servlet-name>MyDefaultServlet</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>
> >   </servlet>
> >
> >  <servlet-mapping>
> >     <servlet-name>MyDefaultServlet</servlet-name>
> >     <url-pattern>/admin/*</url-pattern>
> >   </servlet-mapping>
> >
> >
> > All I am doing here is passing all requests to the 'admin' directory
> > and its children to the default servlet with listings=true.  A
>
> Well, that's not really what you're doing.  The "admin" in your
> url-pattern is a virtual directory in the URL space that bears no
> connection to any real directory, and if there's also a real directory
> named "admin", that's just a coincidence (an unfortunate confusing one
> perhaps).
>
> > simple trick to allow listings on specific directories.  The problem
> > is that when I point the browser to:
> > http://localhost/MyContext/admin/
> >
> > I get the listings for http://localhost/MyContext/
>
> That sounds like the right behavior to me.
>
>
> > Now, If I point the browser to http://localhost/MyContext/admin/admin/
> >
> > ... I get the listings for the right directory.
>
> Well, you're not clearly indicating what's the "right directory", but
> I'm guessing you have a subdirectory admin under your MyContext.
> Again, this behavior sounds right to me for what you have set up above.
>
>
> > Any idea whats going on ?
>
> It's working as you have it set up?  And that doesn't match what you
> want because you don't fully understand this stuff?  (Don't worry,
> most don't :-).
>
> Why don't you say more clearly what you want to do, and perhaps
> someone can comment on that.
>
>
> > And more than that:
> > If I change the pattern from /admin/* to /admin/
> > Everything works fine but than mapping will not kick off for
> > sub-directories of 'admin'
>
> That's because URLs you're using to reach the sub-directories of admin
> no longer match the url-pattern (without the '*').  Again, this sounds
> like the right behavior to me.
>

Milt Epstein
Research Programmer
Integration and Software Engineering (ISE)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message