title: Spring MVC 3: How to provide dynamic content to error page for HTTP 404 errors?
body: <p><strong>What I want:</strong></p>
  
  <p>I want to provide a model to the HTTP 404 error page. Instead of writing a static error Page, which is specified within web.xml, I want to use an
  exception controller, which handles HTTP 404 errors.</p>
  
  <p><strong>What I did:</strong></p>
  
  <p>Removed error page tag from web.xml:</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/httpError.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>and implemented the following exception handler methods inside my AbstractController class:</p>
  
  <pre><code>@ExceptionHandler(NoSuchRequestHandlingMethodException.class)
  public ModelAndView handleNoSuchRequestException(NoSuchRequestHandlingMethodException ex) {
      ModelMap model = new ModelMap();
          model.addAttribute("modelkey", "modelvalue");
          return new ModelAndView("/http404Error", model);
  }
  
  @ExceptionHandler(NullPointerException.class)
  public ModelAndView handleAllExceptions(NullPointerException e) {
          ModelMap model = new ModelMap();
          model.addAttribute("modelkey", "modelvalue");
          return new ModelAndView("/exceptionError", model);
  }
  </code></pre>
  
  <p><strong>What is does:</strong></p>
  
  <p>It works find for exceptions, but not for HTTP error code status 404. It seems like HTTP 404 errors are handled by DispatcherServlet by default. Is it possible to change this behaviour?</p>
  
  <p>And how can I catch 404 errors in my exception handler?</p>