Java Components


Header Filter

This filter allows you to modify the HTTP Response header attributes, based on the request URL. This can be used to, for instance, set the content encoding, prevent browsers from caching a page, etc.

How to Use this Component


This component has no external dependencies.


To use this component, you must include the .jar file in the web application's classpath (either in WEB-INF/lib or in the server's lib folder). You must then add the following code to the web.xml file:



The filter will go through each url line in the configuration file for a given header type, and try matching the regular expression in the 'matches' atrribute to the request URL. If it matches, it will set the header to the specified content. Once a url has matched for a given header, it skips onto the next header; this allows you to set up an 'if / else if / else' structure in the config file.


This filter has two optional init parameters: config and refresh-interval. Config determines the name of the config file, relative to WEB-INF (defaults to 'header.xml'). Refresh Interval determines the length of time (in seconds) before the config file is cached before being re-read.

The config file has the following structure:

<?xml version="1.0"?>
<headers xmlns:xsi=''
 <header name="Cache-Control" type="string">
  <request matches=".*\.jpg">max-age=86400</request>
  <request matches=".*\.css">max-age=172800</request>
  <request matches=".*">max-age=3600</request>