tags:

views:

289

answers:

1

I have a Error404Servlet which is configured as error-page for 404 in web.xml:

   <servlet>
      <servlet-name>Error404</servlet-name>
      <servlet-class>com.foo.bar.Error404Servlet</servlet-class>
   </servlet>

   <error-page>
      <error-code>404</error-code>
      <location>/error404</location>
   </error-page>

In this servlet i have to log the original url that caused 404, but request.getRequestURI() always returns "/error404"

How can i get the original url? The unly ugly method i know is to create filter that puts the original url to request attribute.

+2  A: 

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.

rsp