Reputation: 4690
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?
Upvotes: 1
Views: 1018
Reputation: 43560
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.
Upvotes: 2