1

Can someone explain what <dispatcher>ERROR</dispatcher> means? I cannot find any examples about it. I wanted to handle bad requests (for example when someone makes typo) with Filter and from it to forward to some jsp file. I wrote the following code:

<filter>
    <filter-name>badRequestFilter</filter-name>
    <filter-class>filter.BadRequestFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>badRequestFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

I know that I can use <error-page> in web.xml, but I decide to try this(for practice). But this filter is not called and typos are not catched. What can be the reason for that? Maybe I misunderstood when this types of filters are called. Thanks for your attention.

DPM
  • 1,540
  • 2
  • 18
  • 40

1 Answers1

2

The <dispatcher>ERROR</dispatcher> sets that the filter is only applied to requests dispatched to an error page.

But if you don't specify a error page in web.xml this filter is not invoked. (At least that is the behaviour in Tomcat).

wero
  • 32,544
  • 3
  • 59
  • 84