gzip和介绍和回想方式,可以参考我的这篇博客 gzip的介绍以及web服务器对文件压缩的支持。本文介绍如何借助j2ee的过滤器Filter自己实现gzip对网页文件的压缩。
将该过滤器配置在web.xml中的第一个,实现对*.js文件拦截
package net.aty;
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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GZIPFilter implements Filter
{
@Override
public void destroy()
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException
{
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String ac = httpRequest.getHe