title: Is it possible to have the <error-page> servlet ignore some requests?
body: <p>I have an application that uses the  feature to serve html pages with some error status codes, such as 404. However some of the requests are things like restful services or images which should return the JSON provided by the restful service, or nothing at all in the case of the image. I'm using Tomcat as the servlet container.</p>
  
  <p>To clarify, there are several servlets which some serve images, and others html, plus a filter which serves html for various paths which can configured by the user. The 404 status generally comes from the lack of a filter or servlet mapped to the requested path. Hence the error-page feature is convenient to serve a response for paths that have no filter or servlet to respond to them.</p>
  
  <p>So what I have in web.xml is (ignore spaces between / and *):</p>
  
  <pre><code>... several other mappings above
  
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;RestServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/servlet/rest/ *&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;ErrorPageServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/servlet/errorPage/ *&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  ...
  
  &lt;filter-mapping&gt;
    &lt;!--This will serve content and not forward to the filter chain for certain paths--&gt;
    &lt;filter-name&gt;MainFilter&lt;/filter-name&gt;
    &lt;url-pattern&gt;/ *&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  ...
  
  &lt;error-page&gt;
    &lt;!--Page not found--&gt;
    &lt;error-code&gt;404&lt;/error-code&gt;
    &lt;location&gt;/servlet/errorPage/404&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>Is it possible to have the error page servlet ignore some requests but serve html in the response for others? Or should I use some different method for delivering error pages?</p>
  
  <p>To clarify, what I want is that if someone GETs /foo (which doesn't exist) it goes to the ErrorPageServlet, but for GET /servlet/rest/foo/bar returns 404 response code it doesn't go to the ErrorPageServlet.</p>