Compress Filter ver. 2.2


This is a Java servlet filter (as per Servlet API 2.3). GzipFilter lets you compress output from your jsp,html or Coldfusion pages.

How to use it:

a) download gzipflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml.
 


<filter>
  <filter-name>GzipFilter</filter-name>
  <filter-class>com.cj.gzipflt.GzipFilter</filter-class>
</filter>

c) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>GzipFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

in this case filter will be on for each your .jsp file

And now when you invoke any .jsp page: http://your_host/your_page.jsp GzipFilter will check out client's browser settings. If browser does not support gzip, filter invokes resource normally. If browser does support gzip, output will be compressed.

Also you can set the following initial parameters:

minSize - describes a minimal size for the content to be compressed. By default is not defined (compress always)
mimeInclude - describes a commas separated list of mime types to be compressed. By default is not defined (compress all)
mimeExclude - describes a commas separated list of mime types to be excluded from the compression. By default is not defined (compress all)
expires - describes a cache time (client side cache) in seconds

For example:
 


<filter>
  <filter-name>GzipFilter</filter-name>
  <filter-class>com.cj.gzipflt.GzipFilter</filter-class>
  <init-param>
    <param-name>mimeInclude</param-name>
    <param-value>text/plain,text/html,text/xml</param-value>
  </init-param>
</filter>

Also you can define a server side cache for the compressed data. Requested data will be compressed on the server once so all the sub-sequential requests will be served from cache. In order to switch on server side cache you have to describe an initial parameter dir. This parameter should describe any existing directory on your server (cache directory). You can use it for static files for example and compress them only once (during the first request).

   For downloading:
    Filter:  gzipflt.jar

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: