This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
just to correct the web.xml entry: the <dispatcher>ERROR</dispatcher> element should actually be inside the <filter-mapping> and not in the <filter> element.
I am surprised that it also works when put in the <filter> element. Probably something tomcat allows (not following the specs to the full extend)
Just check the Servlet 2.4 specs, chapter SRV.13.4 Deployment Descriptor Diagram, page 138 (8. filter-mapping Element)
Frits - Is the <dispatcher> element really needed here? The exception is thrown from within the filter so the filter will have been invoked already through the <url-pattern>/*</url-pattern> mapping element. He's not trying to invoke the filter on exception being thrown. I think the problem, as Amitosh said, was just with the incorrect path to the error page.
Is this correct?(just want to make sure my own understanding is correct)
Creator of Enthuware JWS+ V6
I thought that exceptions in filters are not handled by the error-page mechanism, but in fact they are (Servlet 2.4 specs)
SRV.9.9.2 Error Pages A servlet or filter may throw the following exceptions during processing of a request:
- runtime exceptions or errors
- ServletExceptions or subclasses thereof
- IOExceptions or subclasses thereof
The Web application may have declared error pages using the exception-type
element. In this case the container matches the exception type by comparing
the exception thrown with the list of error-page definitions that use the
I tried to figure out what the meaning of the <dispatcher>ERROR</dispatcher> in a <filter-mapping> is, and this is what I found:
SRV.9.9.3 Error Filters The mechanism described in Section SRV.6.2.5, "Filters and the RequestDispatcher" may be used to specify
filters that are applied before an error response is generated.
This looks like you can let a filter be invoked upon an error before the error-page mechanism starts working. However I couldn't get an example working on my Tomcat 5.5 server.
Joined: Mar 10, 2010
As I say - just wanted to make sure I had understood it myself.
For info - from the Servlet 3.0 spec (Section 6.2.5):
By using the new <dispatcher> element in the deployment descriptor, the
developer can indicate for a filter-mapping whether he would like the filter to be
applied to requests when:
The request is being processed with the error page mechanism specified in ”Error
Handling” on page 102 to an error resource matching the <url-pattern>.
This is indicated by a <dispatcher> element with the value ERROR.