title: Custom, dynamic error page with Spring framework
body: <p>I would like my App to display a custom error page when an Exception is thrown. The response containing the page should have the right HTTP status and contain the exception message and possibly other data from the exception object.</p>
  
  <p>I have already tried 2 approaches and neither of them works:</p>
  
  <p>1) Returning a ModelAndView from a <code>AbstractHandlerExceptionResolver</code> subclass - I can generate whatever error page i want but it gets served with a 200 OK HTTP status.</p>
  
  <p>2) Specifying an error page in web.xml - I can't find a way to access the exception.</p>
  
  <p>Ok, solved it. Turned out to be pretty easy actually. I used <code>HttpServletResponse.setStatus</code>. Note that using <code>sendError</code> doesn't work correctly.</p>