Where does Tomcat append / to directory paths?

Posted by Anonymouse on Stack Overflow See other posts from Stack Overflow or by Anonymouse
Published on 2010-05-12T03:40:31Z Indexed on 2010/05/12 3:44 UTC
Read the original article Hit count: 346

Filed under:
|
|
|

Suppose my Tomcat webapps directory looks like this:

webapps/
webapps/fooapp/
webapps/fooapp/WEB-INF/
webapps/fooapp/WEB-INF/web.xml
webapps/fooapp/bardir/

When I make a GET request for /fooapp/bardir, Tomcat sees that webapps/fooapp/bardir is a directory and sends back a 302 to /fooapp/bardir/ (with a slash at the end).

Here is my question: Where in the Tomcat source code does this take place? (I'm looking at 6.0.x but a correct answer for any version would be a great starting point.)

The only reference material I can find on this subject is in the Catalina Functional Specifications which states, regarding the Default Servlet:

On each HTTP GET request processed by this servlet, the following processing shall be performed:

[...]

  • If the requested resource is a directory:
    • If the request path does not end with "/", redirect to a corresponding path with "/" appended so that relative references in welcome files are resolved correctly.

However, this functionality does not appear to be in org.apache.catalina.servlets.DefaultServlet; or at least, it's not there exclusively: if I replace the default servlet in web.xml with a servlet whose servlet-class does not exist, directory paths still come back 302 to add the slash, while every other request comes back with an error as expected.

© Stack Overflow or respective owner

Related posts about tomcat

Related posts about servlets