title: Custom error pages not working in Jetty
body: <p>I notice that, on Jetty (Servlet container), by default, if there is an error, the entire Stack backtrace is sent to the browser, which isn't so good for the live environment.</p>
  
  <p>So I have created a little "servlet-error.html" file and included it in my web app and referenced it from the web.xml.</p>
  
  <p>My web.xml looks like:</p>
  
  <pre><code>&lt;web-app&gt;
    ..
    &lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/servlet-error.html&lt;/location&gt;
    &lt;/error-page&gt;
    &lt;error-page&gt;
      &lt;error-code&gt;503&lt;/error-code&gt;
      &lt;location&gt;/servlet-error.html&lt;/location&gt;
    &lt;/error-page&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The WAR file looks like:</p>
  
  <pre><code>servlet-error.html
  WEB-INF/web.xml
  ...
  </code></pre>
  
  <p>When I don't have the <code>&lt;error-page&gt;</code> section then I get the standard Jetty error (with backtrace), when I have it then I just get a white page in Firefox, and a standard browser error message in Chrome. There are no errors in the Jetty logs like "servlet-error.html could not be found".</p>
  
  <p>I have tried changing the web.xml from  <code>/servlet-error.html</code> to <code>/servlet-error-xxx.html</code> and there was no change (= white page, and no error in Jetty log). So I suspect it can't find by HTML file.</p>
  
  <p>Additional information: The application is written in Wicket, the application is in Wicket "deployment mode", the exception causing the error is being thrown in the constructor of the Application (which seems to bypass Wicket's error handling and hiding of the exception backtrace in deployment mode?). The wicket application is being included via a <code>&lt;servlet&gt;</code> not a <code>&lt;filter&gt;</code>.</p>
  
  <p>P.S. This Jetty is behind an Apache, so is this even the right way to handle this, or should I add something to the Apache config, i.e. "if Jetty returns != 200 then ignore what Jetty returns and instead display this error page..."</p>
  
  <p><strong>Edit</strong>: I have corrected the original reason for the error (i.e. the app now works without error) and now I can surf to <a href="http://mydomain.com/context-root/servlet-error.html" rel="nofollow">http://mydomain.com/context-root/servlet-error.html</a>, whereas before I would get the 500 error if I surf to that static HTML page. I see that I have in my web.xml:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;my-app&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>I suspect that, when Jetty tries to execute the normal request, sees the error, then it tries to fetch the <code>servlet-error.html</code> page, which it also fetches by using the <code>web.xml</code> which falls again into trying to go to the application, which again generates the error.. And presumably to stop an infinite loop, it just displays a blank page to the browser, although something in the log would be nice!</p>
  
  <p>But I'm still not sure what the right way to solve it is....</p>
  
  <p>I added the following, but it didn't help.</p>
  
  <pre><code>&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;default&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>