I have a Error404Servlet which is configured as error-page for 404 in web.xml:
Error404
From the request you can retrieve attributes set by the container in the event of an error:
request.getAttribute("javax.servlet.error.request_uri");
other attributes that can provide usefull information;
javax.servlet.error.status_code
javax.servlet.error.exception_type
javax.servlet.error.message
javax.servlet.error.exception
See also this servlet 2.3 features article.