Create a new servlet that sends an error message using
response.sendError(HttpServletResponse.SC_NOT_FOUND);
and map it to your url template with the corresponding servlet-mapping tag in web.xml . If 403 is valid, then simply set the security-constraint tag with (or without) login-config .
source share