If your web application is also running web services like mine, you might want to avoid those web services clients to see a tomcat predefined (or setup by you) 404 or 500 error page. In order to avoid this you have to write into the output stream something and set the error code. Here the example.

protected void service(HttpServletRequest request,
  HttpServletResponse response) throws IOException {
  try {

    // my regular servlet code here

  } catch (Exception e) {

follow me in twitter @rasensio