You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dan Armbrust <da...@gmail.com> on 2007/12/14 22:10:51 UTC

directory listings per webapp

I want to create a webapp that just lists the content of a directory -
but I don't want to turn on directory listing globally.

I've seen lots of people say it can be done, just do .... but I've yet
to find a working example.  Can someone tell me what I'm missing here?

I have a file:

tomcat/conf/Catalina/localhost/foo.xml

The contents are:

<Context path="/foo" docBase="/dir/foo" debug="0" privileged="false">

</Context>


Now this, all by itself works for creating the webapp, and it will get
a directory listing if I enable global directory listing in the
web.xml file, but I don't want that.

So, I created:

tomcat/server/webapps/billing/WEB-INF/web.xml

The contents are:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <servlet>
        <servlet-name>foo</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>foo</servlet-name>
        <url-pattern>/foo/*</url-pattern>
    </servlet-mapping>

</web-app>


But this doesn't work.

What do I need to do to make this happen?

Thanks,

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: directory listings per webapp

Posted by Dan Armbrust <da...@gmail.com>.
On Dec 14, 2007 4:17 PM, Caldarale, Charles R
<Ch...@unisys.com> wrote:
> > From: Dan Armbrust [mailto:daniel.armbrust.list@gmail.com]
> > Subject: Re: directory listings per webapp
> >
> > Thanks a lot.  I'll see if I can get access to
> > http://wiki.apache.org/tomcat/FAQ/Miscellaneous and update the answer
> > to this question - since the current answer is pretty poor.
>
> In what way?  It describes exactly what must be done - it really is that
> simple.  You created your own problem by putting in a docBase attribute
> telling Tomcat where the webapp was locating and then editing a web.xml
> for an entirely different deployment.

Well, it does now :)

Previously - it said "This is done in TOMCAT_HOME/conf/web.xml by
changing the listings property for the default servlet."

Not exactly very useful in finding out how to do it on a per-app basis.

>
> > It would be nice if someone could update
> > http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html
> > as well, because in general, having documentation basically say  "if
> > you don't know how to do this already, too bad" is just bad practice
> > ;)
>
> I think you misunderstand the meaning of "customize" and perhaps are
> confusing it with "configure".  The section on customization discusses
> only how directory listings are presented.
>

Its about the only other official doc reference that I came up with
after doing a search - so between that and the lacking FAQ, I was left
hunting the mailing list where about 50 people seem to have asked the
question, and most go away with only turning it on globally.

Thanks for your help.

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: directory listings per webapp

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dan Armbrust [mailto:daniel.armbrust.list@gmail.com] 
> Subject: Re: directory listings per webapp
> 
> Thanks a lot.  I'll see if I can get access to
> http://wiki.apache.org/tomcat/FAQ/Miscellaneous and update the answer
> to this question - since the current answer is pretty poor.

In what way?  It describes exactly what must be done - it really is that
simple.  You created your own problem by putting in a docBase attribute
telling Tomcat where the webapp was locating and then editing a web.xml
for an entirely different deployment.

> It would be nice if someone could update
> http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html
> as well, because in general, having documentation basically say  "if
> you don't know how to do this already, too bad" is just bad practice
> ;)

I think you misunderstand the meaning of "customize" and perhaps are
confusing it with "configure".  The section on customization discusses
only how directory listings are presented.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: directory listings per webapp

Posted by Dan Armbrust <da...@gmail.com>.
> Probably not.  You specified a docBase of /dir/foo for the foo webapp,
> but appear to have been editing webapps/foo/WEB-INF/web.xml, which is
> not where you've told Tomcat the app is deployed.  It's extremely bad
> practice to have a directory under the <Host> appBase that's the same as
> one for an app with a docBase that points somewhere else.

Ahh - there we go.  I had tried putting the web.xml file there before
- but at the time, I had the incorrect <url-pattern> in my web.xml.


Thanks a lot.  I'll see if I can get access to
http://wiki.apache.org/tomcat/FAQ/Miscellaneous and update the answer
to this question - since the current answer is pretty poor.

It would be nice if someone could update
http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html
as well, because in general, having documentation basically say  "if
you don't know how to do this already, too bad" is just bad practice
;)


Thanks again,

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: directory listings per webapp

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dan Armbrust [mailto:daniel.armbrust.list@gmail.com] 
> Subject: Re: directory listings per webapp

> I made those two changes - but I still don't get any directory listing

What do you get?

Did you restart Tomcat (or insure that the webapp was otherwise
redeployed)?

What version of Tomcat are you using?

To test what's under discussion, I changed webapps/docs/WEB-INF/web.xml
to include the following:

  <servlet>
    <servlet-name>docsListing</servlet-name>
 
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-clas
s>
    <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>docsListing</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

References to http://localhost:8080/docs/appdev/printer/docs/ now return
a directory listing, whereas before a 404 came back.
 
> Is my path correct for the web.xml file?

Probably not.  You specified a docBase of /dir/foo for the foo webapp,
but appear to have been editing webapps/foo/WEB-INF/web.xml, which is
not where you've told Tomcat the app is deployed.  It's extremely bad
practice to have a directory under the <Host> appBase that's the same as
one for an app with a docBase that points somewhere else.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: directory listings per webapp

Posted by Dan Armbrust <da...@gmail.com>.
I made those two changes - but I still don't get any directory listing
(I can get a file if I name it specifically - so I know that that
context is working)

Is my path correct for the web.xml file?  Or am I missing something else?

Thanks,

Dan

On Dec 14, 2007 3:17 PM, Caldarale, Charles R
<Ch...@unisys.com> wrote:
> > From: Dan Armbrust [mailto:daniel.armbrust.list@gmail.com]
> > Subject: directory listings per webapp
> >
> > <Context path="/foo" docBase="/dir/foo" debug="0" privileged="false">
> > </Context>
>
> Broken record: take out the path attribute; it's not allowed (but it's
> not this problem).
>
> >     <servlet-mapping>
> >         <servlet-name>foo</servlet-name>
> >         <url-pattern>/foo/*</url-pattern>
> >     </servlet-mapping>
>
> Change the <url-pattern> to this:
> <url-pattern>/</url-pattern>
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: directory listings per webapp

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dan Armbrust [mailto:daniel.armbrust.list@gmail.com] 
> Subject: directory listings per webapp
> 
> <Context path="/foo" docBase="/dir/foo" debug="0" privileged="false">
> </Context>

Broken record: take out the path attribute; it's not allowed (but it's
not this problem).

>     <servlet-mapping>
>         <servlet-name>foo</servlet-name>
>         <url-pattern>/foo/*</url-pattern>
>     </servlet-mapping>

Change the <url-pattern> to this:
<url-pattern>/</url-pattern>

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: directory listings per webapp

Posted by Dan Armbrust <da...@gmail.com>.
There is a typo in the below.

This
> tomcat/server/webapps/billing/WEB-INF/web.xml

Should have been

tomcat/server/webapps/foo/WEB-INF/web.xml

So thats not the problem.

Dan


On Dec 14, 2007 3:10 PM, Dan Armbrust <da...@gmail.com> wrote:
> I want to create a webapp that just lists the content of a directory -
> but I don't want to turn on directory listing globally.
>
> I've seen lots of people say it can be done, just do .... but I've yet
> to find a working example.  Can someone tell me what I'm missing here?
>
> I have a file:
>
> tomcat/conf/Catalina/localhost/foo.xml
>
> The contents are:
>
> <Context path="/foo" docBase="/dir/foo" debug="0" privileged="false">
>
> </Context>
>
>
> Now this, all by itself works for creating the webapp, and it will get
> a directory listing if I enable global directory listing in the
> web.xml file, but I don't want that.
>
> So, I created:
>
> tomcat/server/webapps/billing/WEB-INF/web.xml
>
> The contents are:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>     <servlet>
>         <servlet-name>foo</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>foo</servlet-name>
>         <url-pattern>/foo/*</url-pattern>
>     </servlet-mapping>
>
> </web-app>
>
>
> But this doesn't work.
>
> What do I need to do to make this happen?
>
> Thanks,
>
> Dan
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org