我正在创建一个Java过滤器来处理我的Web应用程序的ETag。
这是我的代码:
<!-- 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
}
}
}
在WEB.xml中。我像这样配置我的ETagFilter
<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>
如果我像上面那样配置我的过滤器。使用DispatcherType的唯一请求是由Filter处理REQUEST。具有调度程序类型的其他请求(如FORWARD,INCLUDE,ERROR,ASYNC)将不会由ETagFilter处理。
我的问题是:我是否必须在我的etag过滤器映射中添加其他调度程序类型(FORWARD,INCLUDE,ERROR,ASYNC)才能正确配置我的ETagFilter? (如下所示)
<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>
在我看来。请求就足够了。你的想法怎么样?谢谢,