I am creating a Java filter to handling ETag for my web application.
Here is my code:
<!-- language: java -->
public class ETagFilter implements Filter {
public doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
if ( (request instanceof HttpServletRequest) == false ) {
chain.doFilter(request, response);
} else {
ETagResponseWrapper wrapper = new ETagResponseWrapper((HttpServletResponse)response);
filterChain.doFilter(request, wrapper);
byte[] body = wrapper.toByteArray();
// ....
// Other process
}
}
}
in WEB.xml. I configure my ETagFilter like this
<filter>
<filter-name>ETagFilter</filter-name>
<filter-class>myapp.ETagFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ETagFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
If I configure my filter like above. ONLY request with DispatcherType is REQUEST handled by the Filter. Other request with dispatcher types like FORWARD, INCLUDE, ERROR, ASYNC will NOT handled by ETagFilter.
My question is: Do I have to add other dispatcher types (FORWARD, INCLUDE, ERROR, ASYNC) into my etag filter mapping in order to configure my ETagFilter correctly? (like below)
<filter-mapping>
<filter-name>ETagFilter</filter-name>
<url-pattern>*.html</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
In my opinion. REQUEST is enough. How about your ideas. Thanks,