title: Precedence of filter over servlet in Tomcat
body: <p>I have Apache Tomcat Version 7.0.26 running.</p>
  
  <p>A have a JAX-RS servlet under /test, which calls jsps which in tourn should be handled by the Tomcat servlet engine. </p>
  
  <p>E.g.,
  <code>/test</code> should be handled by jersey, but <code>/test/result.jsp</code> should be handled by the JSP engine.</p>
  
  <p>I don't want the user to see different urls, therefore, I rewrite the jsp URLs to /jsp internally.</p>
  
  <p>Config is like that:</p>
  
  <p><a href="http://www.tuckey.org/urlrewrite/" rel="nofollow noreferrer">UrlRewriteFilter</a> (in <code>urlrewrite.xml</code>):</p>
  
  <pre><code>&lt;rule&gt;
      &lt;from&gt;^/([^j][^s][^p].*\.jsp)&lt;/from&gt;
      &lt;to&gt;/jsp/$1&lt;/to&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p><code>web.xml</code>:</p>
  
  <pre><code>&lt;filter&gt;
     &lt;filter-name&gt;UrlRewriteFilter&lt;/filter-name&gt;
     &lt;filter-class&gt;org.tuckey.web.filters.urlrewrite.UrlRewriteFilter&lt;/filter-class&gt;
     &lt;!-- set the amount of seconds the conf file will be checked for reload
     can be a valid integer (0 denotes check every time,
        empty/not set denotes no reload check) --&gt;
     &lt;init-param&gt;
       &lt;param-name&gt;confReloadCheckInterval&lt;/param-name&gt;
       &lt;param-value&gt;0&lt;/param-value&gt;
     &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;UrlRewriteFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
  &lt;/filter-mapping&gt;
  
  &lt;servlet&gt;
    &lt;servlet-name&gt;Test&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
      &lt;param-value&gt;test&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Test&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/test/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>A call to <code>/xyz.jsp</code> is redirected to <code>/jsp/xyz.jsp</code>. A call to <code>/test/xyz.jsp</code> leads to <code>404 - Servlet Test is not available</code>. I thought that filters have precedence over servlets, don't they?</p>
  
  <p>I am aware of the related question <a href="https://stackoverflow.com/questions/2957165/servlet-vs-filter">Servlet vs Filter</a>, but they don't state anything about the precedence.</p>
  
  <p>BTW: <a href="http://ocpsoft.org/prettyfaces/" rel="nofollow noreferrer">PrettyFaces</a> seems to be similar to UrlRewriteFilter, but I haven't tried it yet. I (currently) like UrlRewriteFilter more.</p>
  
  <p>EDIT: The question <a href="https://stackoverflow.com/questions/7210546/how-to-mix-server-side-jax-rs-call-with-native-files-without-prefix">How to mix server-side Jax-rs call with native files without prefix?</a> asks the question behind my question.</p>