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) {
    response.setStatus(500);
    response.getWriter().println("");
  }
}

follow me in twitter @rasensio

Categories: java

Rodrigo Asensio

Apasionado por la tecnología

Leave a Reply

Your email address will not be published. Required fields are marked *