<!-- 去掉tomcat的etag和Last-Modified响应头的过滤器 --> <filter> <filter-name>noetag</filter-name> <filter-class>com.epoint.basic.filter.EpointNoETagFilter</filter-class> </filter> <filter-mapping> <filter-name>noetag</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
此过滤器放在web.xml的过滤器后面即可
package basic.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
/**
*
* 禁用tomcat的ETag和Last-Modified响应头
*
* @author Epoint
* @version 2023年2月9日
*/
public class EpointNoETagFilter implements Filter
{
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response)
{
public void setHeader(String name, String value) {
if (!"etag".equalsIgnoreCase(name) && !"Last-Modified".equalsIgnoreCase(name)) {
super.setHeader(name, value);
}
}
});
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
标签:缓存,name,tomcat,void,public,过滤器,import,servlet,javax
From: https://blog.csdn.net/m0_61200771/article/details/143329514