1

I am trying to redirect erroneous page requests - 404 errors - to a custom error page. In order for my servlet, instead of the root servlet, to handle these requests, I entered the following url-pattern:

<url-pattern>/</url-pattern>

Unfortunately, this also catches embedded requests for files like *.js, *.css, *.png, *.jpg, and other such files. Is there a way in the deployment descriptor to specify an exclusive pattern? Say, "everything EXCEPT requests with x extension"?

Or is there another way around this that I'm not seeing?

Magsol
  • 4,640
  • 11
  • 46
  • 68

1 Answers1

2

You can just declare an error page for HTTP 404 errors in the DD as follows.

<error-page>
  <error-code>404</error-code>
  <location>/notFound.jsp</location>
</error-page>

The container (Tomcat in your case) will then capture any HTTP 404s and forward them on to the page you specify (/notFound.jsp in the example above).

There's some documentation at Sun, and some more at Google Code.

brabster
  • 42,504
  • 27
  • 146
  • 186
  • Awesome, that's exactly what I needed. Not sure why I couldn't figure that out on my own, but thank you very much. – Magsol Sep 29 '09 at 23:45