If-Modified-Since filter ver. 1.2

This is a Java servlet filter (as per Servlet API 2.3). This filter lets you proceed If-Modified-Since header in the request. The If-Modified-Since header field is used with the GET method to make it conditional: if the requested resource has not been modified since the time specified in this field, a copy of the resource will not be returned from the server. In this case a status code 304 (not modified) will be returned with empty body. So you can save bandwidth for static files for example.
This filter aslo sets Last-Modified header in the response.

How to use it:

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

b) describe this filter in web.xml.
 


<filter>
  <filter-name>IfModFilter</filter-name>
  <filter-class>com.cj.response.IfModFilter</filter-class>
</filter>

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


<filter-mapping>
  <filter-name>IfModFilter</filter-name>
  <url-pattern>/html/*</url-pattern>
</filter-mapping>

and filter will be on for all your files in directory html.

Also you can use this filter as a cache solution for your sites. An initial parameter delay describes a time (in seconds) the actual response will be delayed. This time will be added to the time provided in if-modified-since header during the status code calculation. E.g.:
 


<filter>
  <filter-name>IfModFilter</filter-name>
  <filter-class>com.cj.response.IfModFilter</filter-class>
  <init-param>
   <param-name>delay</param-name>
   <param-value>600</param-value>
  </init-param>
</filter>

So if the requested resource has not been modified since the time specified in if-modified-since plus 600 seconds, the client will get a 304 status code. This parameter lets you provide a delayed response that could be useful in case of heavy traffic for example.

See also Last-Modified filter.

   For downloading:

    If-Modified-Since package:  ifmodflt.jar
 

 ©  Coldbeans     Comments?

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

Also in JSOS: