aspose file tools*
The moose likes Servlets and the fly likes How to call HEAD method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call HEAD method ?" Watch "How to call HEAD method ?" New topic
Author

How to call HEAD method ?

Janelle Goldsmith
Greenhorn

Joined: Mar 20, 2003
Posts: 12
I want to call the HEAD method on a servlet.
If in my HTML code, I specify -
<form name="testHead" action="/servlet/servletName" method="HEAD">
and the servlet handles the HEAD method in the sense that the doGet() method returns if the method type is HEAD.
When I run it, the servlet returns the code retured by the entire doGet() method. This shows that the doGet() method does not realize that it is a HEAD method and it should return back without procesing further.
The application server is Tomcat 4.0.
Benny Tang
Greenhorn

Joined: Aug 03, 2003
Posts: 26
Hi,
Have you providing the doHead() method is the servlet class you write? Is this works?
Benny
Mahesh swami
Greenhorn

Joined: Aug 13, 2002
Posts: 26
What a doHead() method does is , it calls doGet() with modified response object which supresses all the response body and sends only the headers
-Mahesh
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
Can you please elaborate it.
Thanks & Regards,
M.S.Raman.
Janelle Goldsmith
Greenhorn

Joined: Mar 20, 2003
Posts: 12
I want to make a request from the browser which just returns the header of the response.
This means, I need to call the HEAD method of the servlet.
Which as mentioned in this discussion earlier, would get transferred to the GET method.
My implementation of the the GET method checks for the method type, and if it is HEAD, it just returns before starting any processing for the GET method.
When I call the servlet from the browser with method type as HEAD, it brings back whatever the doGet()(whole of doGet()) returns.
So, this indicates that the doGet() method does not recognize the method type as HEAD and keeps processing for the GET method and brings back the complete data.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

You cannot call the doHead ,doPut or doTrace methods. I think you can it from applet.
http://www.coderanch.com/t/355304/Servlets/java/doPut-doHead-example
http://www.coderanch.com/t/353895/Servlets/java/examples-doOptions-doTrace-doHead
[ September 04, 2003: Message edited by: Pradeep Bhat ]

Groovy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
Where in the world did the idea that you can't doHead, doPut or doTrace come from???
Look at the HttpServlet class API
It has the methods for all of DELETE, GET, HEAD, OPTIONS, POST, PUT, and TRACE - the service method directs a request accordingly.
Bill
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Can you call it from a HTML page? I have written a servlet with doHead method. I am submitting a html form with method "HEAD" and I find that the doHead method does not get called.
Originally posted by William Brogden:
Where in the world did the idea that you can't doHead, doPut or doTrace come from???
Look at the HttpServlet class API
It has the methods for all of DELETE, GET, HEAD, OPTIONS, POST, PUT, and TRACE - the service method directs a request accordingly.
Bill

[ September 05, 2003: Message edited by: Pradeep Bhat ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://forum.java.sun.com/thread.jsp?forum=33&thread=361255
http://forum.java.sun.com/thread.jsp?forum=33&thread=214992
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
My understanding of the use of the FORM tag is that METHOD can only be GET or POST - I bet that if you use HEAD the browser does a GET by default. HEAD does not make sense as a form method anyway.
You would have to use a HttpURLConnection to do a HEAD request.
Bill
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

True. The valid values for method attribute in the FORM tag are GET and POST. This means that I cannot use a browser to call doHead, doTrace,doPut methods.

Originally posted by William Brogden:
My understanding of the use of the FORM tag is that METHOD can only be GET or POST - I bet that if you use HEAD the browser does a GET by default. HEAD does not make sense as a form method anyway.
You would have to use a HttpURLConnection to do a HEAD request.
Bill

[ September 07, 2003: Message edited by: Pradeep Bhat ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to call HEAD method ?