Tuesday, September 07, 2010

404! Why? Where from?

Alright, so you got 404'd! Things aren't that bad because you handled it nicely, but the real question you have on the tip of your tongue is "What URL caused this 404?"

The request could receive the following attributes that can indicate what caused the error

Where did it come from?

To get the original URL of the request that is in trouble, look at javax.servlet.error.request_uri request attribute.

String uri = (String) request.getAttribute("javax.servlet.error.request_uri");

What caused it?

To cause of the error can be a HTTP error or an exception that was not handled by the web application and propagated all the way up. The three attributes that will give you more insight are:

  • javax.servlet.error.status_code:
    An Integer telling the error status code, if any
  • javax.servlet.error.exception_type:
    A Class instance indicating the type of exception that caused the error, if any
  • javax.servlet.error.message:
    A String telling the exception message, passed to the exception constructor
  • javax.servlet.error.exception:
    A Throwable object that is the actual exception thrown

No comments:

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.