title: Jetty servlet mapping with web.xml does not work
body: <p>I am building a Java web app with Jetty and I am trying to map servlets with <code>web.xml</code>, however, that is not working - all of the mapped servlet URLs return a Jetty 404 error.</p>
  
  <p>Here is my <code>/src/main/webapp/WEB-INF/web.xml</code> file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
           version="3.1"&gt;
  
    &lt;error-page&gt;
      &lt;error-code&gt; 404 &lt;/error-code&gt;
      &lt;location&gt; /error/404 &lt;/location&gt;
    &lt;/error-page&gt;
  
  
    &lt;servlet&gt;
      &lt;servlet-name&gt; MainPage &lt;/servlet-name&gt;
      &lt;servlet-class&gt; xx.yyy.zzz.vvvvvvvv.HelloPageHandler &lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt; MainPage &lt;/servlet-name&gt;
      &lt;url-pattern&gt; /* &lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;filter&gt;
      &lt;filter-name&gt; HeaderFilter &lt;/filter-name&gt;
      &lt;filter-class&gt; xx.yyy.zzz.vvvvvvvv.HeaderFilter &lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt; HeaderFilter &lt;/filter-name&gt;
      &lt;url-pattern&gt; /* &lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>(Real package name is hidden, for obvious reasons)</p>
  
  <p>The main launcher class code:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void main(String[] args) {
          Logger.getGlobal().log(Level.FINE, "Starting server");
          try {
              Server server = new Server(10800);
              ServletHandler servletHandler = new ServletHandler();
  
              server.start();
              server.join();
          } catch (Exception e) {
              Logger.getGlobal().log(Level.SEVERE, "Exception while starting server", e);
          }
      }
  </code></pre>
  
  <p>However, when trying to view some mapped URL:</p>
  
  <p><a href="https://i.stack.imgur.com/hfR5G.png" rel="nofollow noreferrer">Jetty error</a></p>
  
  <p>I did try:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void main(String[] args) {
          Logger.getGlobal().log(Level.FINE, "Starting server");
          try {
              Server server = new Server(10800);
  
              ServletHandler servletHandler = new ServletHandler();
  
              server.setHandler(servletHandler);
              ServletHolder holder = new ServletHolder(new HelloPageHandler());
              servletHandler.addServletWithMapping(holder,  "/abcd/*");
              servletHandler.addFilterWithMapping(HeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
  
              server.start();
              server.join();
          } catch (Exception e) {
              Logger.getGlobal().log(Level.SEVERE, "Exception while starting server", e);
          }
      }
  </code></pre>
  
  <p>However, adding each servlet in the main method individually is repetitive and seems silly and incorrect. Any ideas why this could be happening?</p>