PDA

View Full Version : How to apply filter to 404's in servlet 2.3?


jboring
Aug 10th, 2007, 05:06 PM
I would like to have a filter invoked when ever a request comes in that does not represent a valid page/url (404's). What we are doing now is mapping the error-code to a jsp page that redirects via <c:redirect url="unknown.req"> (see code below) but of course that is another round trip and therefore not optimal.



<filter-mapping>
<filter-name>routerRedirectInputFilter</filter-name>
<url-pattern>/unknown.req</url-pattern>
</filter-mapping>

.....

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


I have tried replacing the c:redirect with a jsp:forward but this does not invoke the filter. I suspect this is not possible with v2.3 but might be with v2.4. Perhaps I will have to use AOP and inject the process I now have in the filter into the controller.

Thoughts?