This is written abotut the doHead() method in the servlet api
IReceives an HTTP HEAD request from the protected service method and handles the request. The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length. The HTTP HEAD method counts the output bytes in the response to set the Content-Length header accurately.
If you override this method, you can avoid computing the response body and just set the response headers directly to improve performance. Make sure that the doHead method you write is both safe and idempotent (that is, protects itself from being called multiple times for one HTTP HEAD request).
If the HTTP HEAD request is incorrectly formatted, doHead returns an HTTP "Bad Request" message.
what if we dont override the doHead() method ... & keep the method in the html as method = head then will the client evaluate the response body ?? ... i just can not follow what is tryin to be said in the api ... some one please explain !!! with a example if possible
According to the HTTP spec, HEAD is identical to GET, except that the response body is not returned. What the javadocs mean is that the default implementation will -when it receives a HEAD request- execute it as a GET request, but then throw away the response body which would have been sent, and just return the response header.
But executing the GET may be unnecessary - the server-side code may have all the information needed for creating the response headers. In that case, the doHead method should be overridden to NOT execute the GET, but just return those headers.
The whole concept is a bit theoretical, because HEAD isn't used by HTML, so it's not easy to see what is going on, and why. One use for HEAD might be an intelligent browser that is being asked to retrieve via GET a large resource (maybe a 50MB file). If the browser has the file in the cache, it wouldn't need to download it again, but it would need to make sure that the file hasn't changed since the download. That's what a HEAD might be used for, because the response headers would contain the date on which the file was last modified.
Does that make things clearer? [ July 21, 2007: Message edited by: Ulf Dittmer ]