title: How to dispatch servlet requests to Jersey resource methods
body: <p>I am wondering if it is possible to dispatch a request from a servlet to a Jersey (JAX-RS implementation) resource class. I am trying to do it but it doesn't seem to work and according to my logging, the jersey resource is never reached.</p>
  
  <p>Code examples are below. Is what I'm trying to do impossible for some reason?</p>
  
  <p>Please note, the Jersey resource <strong>works correctly when I access it directly in a web browser</strong> via the address bar.</p>
  
  <p><strong>Also please note that 'RequestDispatcher.forward()' works as expected. It is just 'include' that doesn't.</strong></p>
  
  <p><strong>The servlet</strong>    </p>
  
  <pre><code>//The Jersey dispatcher url-filter is set to '/api/*'
  String servletID = "/api/items";
  RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(servletID);
  dispatcher.include(request, response);    
  </code></pre>
  
  <p><strong>The Jersey resource</strong></p>
  
  <pre><code>@GET @Path("/items")
  @Produces ({MediaType.TEXT_XML})
  public JAXBElement&lt;Items&gt; getItems(@PathParam("project") String project) throws       IOException, JAXBException {
  
      log.debug("reached getItems");
  
      //Omitted code that returns 'Items' object wrapped in JAXBElement
  
  }
  </code></pre>
  
  <p><strong>Relevant parts of web.xml</strong></p>
  
  
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;jerseyDispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
          &lt;param-value&gt;uk.co.web.api.resource&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;jerseyDispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>