I tried to test dispatcher with ERROR in the web.xml and couldn't able to test. I configured web.xml with error-page and changed my HelloServlet to throw Exception but the MyFilter never triggered when there is an error.
I think HelloServlet should be catching the exception. The called to the filter will be made in case Servlet is invoked by means of error thrown mechanism from some other servlet.
<filter>
<filter-name>HelloWorldFilter</filter-name>
<filter-class>com.TestHelloWorldFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HelloWorldFilter</filter-name>
<servlet-name>HelloWorldServ</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>HelloWorldFilter</filter-name>
<servlet-name>TestErrorDispServ</servlet-name>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<exception-type>java.lang.ClassCastException</exception-type>
<location>/servlet/TestErrorDispServ</location>
</error-page>
Hope this helps.