title: 404 when dispatching from servlet served with a wildcarded path
body: <p><strong>tl;dr:</strong> Dispatching to an absolute path from a servlet fails when it (the servlet) is bound with a wildcard (<code>/a/*</code>) but not when bound explicitly (<code>/b/b</code>)</p>
  
  <hr>
  
  <p>I have a Guice webapp with a servlet that dispatches traffic to an HTML file stored in WEB-INF:</p>
  
  <pre><code>@Singleton
  public class MyServlet extends HttpServlet {
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          request.getRequestDispatcher("/WEB-INF/hello.html").forward(request, response);
      }
  }
  </code></pre>
  
  <p>It is configured with a <code>GuiceServletContextListener</code>...</p>
  
  <pre><code>public class MyApp extends GuiceServletContextListener {
      @Override
      protected Injector getInjector() {
          return Guice.createInjector(new MyModule());
      }
  
      private static final class MyModule extends ServletModule {
          @Override
          protected void configureServlets() {
              serve("/a/*").with(MyServlet.class);
              serve("/b/b").with(MyServlet.class);
          }
      }
  }
  </code></pre>
  
  <p>...and a <code>web.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
           version="2.4"&gt;
  
      &lt;display-name&gt;MyApp&lt;/display-name&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;com.google.inject.servlet.GuiceFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;                                                
      &lt;/filter-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;test.MyApp&lt;/listener-class&gt;
      &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I launch it in Tomcat and go to <code>localhost/b/b</code> and I see my <code>hello.html</code> page. However, when I go to <code>localhost/a/a</code>, I get a <code>HTTP Status 404 - /WEB-INF/hello.html</code>. This seems very strange to me as the two paths, wildcarded or not, are bound to the same servlet, as well as the HTML path being absolute and not really up for interpretation.</p>
  
  <p>Is this the result of a bug, some (to me unknown) behavior I haven't accounted for, or sheer misconfiguration on my part?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Based on some further experimentation, <code>include</code> seems to work as expected, which suggests to me that <code>forward</code> has some additional behavior I've missed. Using <code>include</code> will probably hold me over for now, but I'd still like to know what I'm doing wrong.</p>