jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

DefaultServlet behaviour wrong for `welcomeFiles`

Open janbartel opened this issue 2 years ago • 1 comments
trafficstars

Jetty version(s) 10/11/12

The behaviour for welcomeFiles = true or exact does not match the javadoc.

The desired behaviour is explained in the javadoc for jetty-10:

 *  welcomeServlets   If true, attempt to dispatch to welcome files
 *                    that are servlets, but only after no matching static
 *                    resources could be found. If false, then a welcome
 *                    file must exist on disk. If "exact", then exact
 *                    servlet matches are supported without an existing file.
 *                    Default is false.

However in jetty-10, 11 and 12, that is not the behaviour - a resource must exist or we throw a 404.

See in jetty-10 ResourceService around lines 240/245. See in jetty-12 DefaultServlet around lines 458/462.

For example given:


        _contextHandler = new ServletContextHandler();
        _contextHandler.setContextPath("/context");
        _contextHandler.setBaseResourceAsPath("/some/path/contextResources");
        _contextHandler.setWelcomeFiles(new String[] {"index.x"});
        ServletHolder rHolder = _contextHandler.addServlet(DefaultServlet.class, "/r/*");
        rHolder.setInitParameter("welcomeServlets", "true");
        _contextHandler.addServlet(RogerThatServlet.class, "*.x");

A request to /context/r/ should dispatch to /index.x, but will not proceed to the RogerThatServlet unless the directory /some/path/contextResources/r exists, which it should not need to according to the javadoc.

janbartel avatar Sep 28 '23 01:09 janbartel