aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in doHead() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in doHead() method" Watch "Doubt in doHead() method" New topic
Author

Doubt in doHead() method

anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
Hi

These are statements from servlet specification

The doHead method in HttpServlet is a specialized form of the doGet method that returns only the headers produced by the doGet method.

I tried a small program

1) i override service(HttpServletRequest req,HttpServletResponse res)
2) i had made a call to doHead(req,res)

Now i have a doubt here,
Here we are sending the same request and response to say doGet(),doPost(),...

Because we are sending the same req and res to every method,we can get every information in every method.

So what is specail of those statements written in specification


Can any body explain me?


Thanks

Anil Kumar
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226

The doHead method in HttpServlet is a specialized form of the doGet method that returns only the headers produced by the doGet method.


Perfectly correct.


Because we are sending the same req and res to every method,we can get every information in every method.


Only because you have overridden service.
I guess you could say that in it's current state, your servlet may not be complying with the specification.

In order to comply:
- don't override service. If you've extended HttpServlet, it will determine when a HEAD HTTP request has been received and will call doHead(). Triggering one of those may be tricky though!

Hope that clears things up a little.

MG
[ June 19, 2007: Message edited by: Mark Garland ]

28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
Hi

If i don't override service() and doGet(),then how the container can call the doHead() method,Because by default the container call doGet() ,if we don't specify any thing.


So how to call the doHead().




Thanks

Anil Kumar
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
Calling doHead() would be achieved by a client sending in a HTTP request of type HEAD.

You're right - by default, the browser uses GET.

Exactly how you would send this request in, I'm not sure. There are a number of clients I have seen that can be used for testing this sort of thing, but I don't have any links.

However, overriding service could be used for testing, but leaving it in a delivered product just sounds like a bodge to me.
[ June 19, 2007: Message edited by: Mark Garland ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
[Anil]:

So how to call the doHead().


Charles Lyons: "SCWCD study companion"


The doHead method default implementation returns a header by delegating processing to the doGet method and then ignoring the body.
...
...
HEAD method is defined to return the headers for ther GET method, and no
others. If the doGet method is not overridden, the doHead method should return the appopriate status code: either 400 for HTTP/1.0 or 405 for
HTTP/1.1.
...
...


Thanks,


cmbhatt
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by anil kumar:
i override service(HttpServletRequest req,HttpServletResponse res)


Why are you overriding the service method.Simple override the doHead method and service method would take care to transfer the control to doHead method in case the HTTP method in the request is HEAD.

I do not think you can use browser to make a call using HTTP HEAD method.You can use jakarta HTTP client project for making a HEAD request.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in doHead() method