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.
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
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
Joined: Jun 03, 2000
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
Joined: Jan 20, 2001
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.
Joined: Jul 18, 2001
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 ]