Share on Google+Share on Google+

Support for ETag

In this section, you will learn about how to use ETag in Spring MVC.

Support for ETag

In this section, you will learn about how to use ETag in Spring MVC.

An entity tag or Etag is part of HTTP which provides web cache validation mechanism. This mechanism saves bandwidth because a full response need not send if content is not modified. HTTP/1.1 supported web server utilize Etag , which is an HTTP response header, to find out changes at provided URL.

It can be a good replacement of Last-Modified header. The client can utilize the Etag header, returned by the server with a representation, in subsequent GETs, in an If-None-Match header. If the content at given URL is not changed, the server returns 304:Not Modified.

Servlet filter ShallowEtagHeaderFilter provides ETag support and since it is a plain Servlet Filter , it can be implement with any framework. The ShallowEtagHeaderFilter cache the JSP/ content and creates an MD5 hash over that and returns MD5 hash as an ETag header in the response.

Next time the same resource is requested by a client, it utilizes that MD5 hash as the If-None-Match value. The filter notices this and view is again render by it. After rendering , it compares the two hashes for equality. If they are equal - 304 is returned. This filter ShallowEtagHeaderFilter doesn't save processing because it renders each time to compare hash. It only saves bandwidth since rendered response is not sent back on the bandwidth.

ShallowEtagHeaderFilter can be configure in the web.xml as below :





Posted on: January 31, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Support for ETag  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image