Introduction To Tek271 GzipServletFilter
A Java open source servlet filter to compress HTTP responses using GZip.
This software is open source, free, and uses LGPL license.
tek271.gzipServletFilter.2007.11.28.zip: Source, JAR, JavaDocs.
Modern browsers can receive HTTP Response data in a compressed format (GZip). This compression can decrease the bandwidth requirement of web pages, and speeds up the display of these pages at the client. If you are running a Java web application you can use the Tek271 GzipServletFilter to transparently compress the data you send to the client. This compression will occur without any modifications or changes to your application's code.
Tek271 GzipServletFilter works as a Servlet Filter you install with your application. It will detect if the browser supports GZip compression, and if it does, the filter will compress the response data and sends it back to the client.
2. Required Setup
You need JDK 5 or higher.
Download Tek271 GzipServletFilter zip file. Unzip it. In the build directory, find tek271.gzipServletFilter.jar file.
Make sure to put tek271.gzipServletFilter.jar in your application's class path. Usually this could be in your application's WEB-INF/libdirectory.
Add the following to your application's web.xml :
<init-param> <!-- optional: log filter usage to console -->
<filter-mapping> <!-- compress the response for any html request -->
<filter-mapping> <!-- compress the response for any jsp request -->
And that's it.
The setup above will cause all requests for *.html or *.jsp files to have GZip compressed responses. (If the client's browser does not support compression, then the filter will not do any compression).
Two Servlet Filters Every Web Application Should Have by Jayson Falkner: This article on www.onJava.com shows how to create a compression servlet filter and provides a simple implementation.
Apache Tomcat example CompressionFilter: A compression filter provided as an example with Tomcat.
If you search the internet for "java compression filter" you should find several other implementations.
You may wonder why create another implementation with all the above examples. I had the following reasons:
All the implementations I found where either examples with "examples quality",
or had licensing I did not want to use.
Version 1.00, 2007.11.28
First public release