This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HEAD requests. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HEAD requests." Watch "HEAD requests." New topic
Author

HEAD requests.

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi,
There are a few things which I am not too sure regarding how Servlet 2.3 handles GET and HEAD requests. Please help.
1. If doHead() method in HttpServlet is overridden, will it be called by the server when there is a HEAD request?
2. Is the HttpServletResponse parameter in the doHead() method a special type of response object which contains no content (only status line and headers)?
3. Since there is a doHead() method available, and if doGet() is overridden, will a OPTIONS request cause doOptions() to still return the header :
Allow : GET, HEAD, TRACE, OPTIONS
Note that HEAD is in the Allow header.
Thanks in advance.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
As a corollory to this qstn....How do I send a HEAD request?
My understanding is that this is done implicitly by the browser and we don't get involved.
Ofcourse I can try to submit a form with a HEAD method and see what happens. But thought I will ask what others think?
Thanks.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236
Meng :
1. If doHead is overrriden then it will be called by the server.This method creates a special response body as you correctly said by instantiating a class called "NobodyResponse" and passes the original request object and this newly created object to the doGet() method.
2.yes, it is a different response object.
3.if doOptions() is overriden and so is doGet method then GET and HEAD headers are set.Rest of them are ignored.
Hope this helps,
Manjunath
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

3.if doOptions() is overriden and so is doGet method then GET and HEAD headers are set.Rest of them are ignored.

Could you please elaborate on the doOptions() please. Not very familiar with this...I have to go back 5 maybe 6 months back.
Thanks.
- satya
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi Manjunath,
Assume doGet() is overridden and doHead() is not.
When a OPTIONS request is sent, doOptions will return the header :
Allow : GET, HEAD, TRACE, OPTIONS
This is what the Servlet API 2.3 specs. says:
"The OPTIONS request determines which HTTP methods the server supports and returns an appropriate header. For example, if a servlet overrides doGet, this method returns the following header:
Allow: GET, HEAD, TRACE, OPTIONS "
What I dont understand is this:
Why is HEAD in the Allow header?
If by overriding doHead() will cause the servlet to handle HEAD requests then doOptions() (asumming only doGet() is overridden) should return only
Allow : GET, TRACE, OPTIONS
Please advise.
Thanks.
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236
Hello Meng,
I guess you are right..When doOptions is overridden it does set and allow GET,HEAD,OPTIONS and TRACE options.Sorry about that..
I guess (and i am only guessing!!) the only reason for HEAD to be set by doOptions() when only doGet() is overridden is probably because doGet() can also support HEAD requests.
Hope this helps,
Manjunath
[ February 05, 2002: Message edited by: Manjunath Subramanian ]
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
I recently tried overriding the doHead() and doGet() methods of my servlet and set the METHOD of my HTML FORM to "HEAD". Why is it that doGet() always get called instead of doHead()?


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: HEAD requests.
 
Similar Threads
About doGet() adn doHead()
Doubt in doHead() method
doHead() example needed
GET and HEAD requests
Just wanted to share this....about doGet