Response filter ver. 1.2

This is a Java servlet filter (as per Servlet API 2.3). This filter lets you add headers to the response. Filter assumes that initial parameters provide a set of pairs: header name/header value. Servlet reads own initial parameters and adds described headers to the response.

How to use it:

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

b) describe this filter in web.xml. In this example we are adding Cache-Control header that controls client side cache. In other words this example shows how to use this filter for caching content in HTTP 1.1 environment. Of course, you can set more initial parameters.
 


<filter>
  <filter-name>ResponseFilter</filter-name>
  <filter-class>com.cj.response.ResponseFilter</filter-class>
  <init-param>
    <param-name>Cache-Control</param-name>
    <param-value>max-age=600</param-value>
  </init-param>
</filter>

d) describe a mapping for this filter in web.xml. E.g.:
 


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

in this example filter will be on for the each .jsp file in /a subdirectory. It means that files from this path will be cached on the client side for 10 minutes (600 seconds). Of course you can use more than one initial parameter as well as all the headers supported by HTTP.

   For downloading:

    Response package:  responseflt.jar
 

 ©  Coldbeans     Comments?

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

Also in Coldtags: