The API provides methods to do this without explicitly specifying the error page in your code. See the answer to this question for an example: How do I throw a 404 error from within a java servlet?
The main benefit of the answer given is that the servlet container will ensure the correct HTTP error code is returned as part of the response.