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: 12871
    
    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: 12871
    
    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 ]
Ariel Adauta
Greenhorn

Joined: Dec 26, 2014
Posts: 1

Janelle Goldsmith wrote: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.



Hello Janelle Goldsmith.
Probably it's too late since this is from 2003.

I'm new in "coderanch", I had the same question, and I saw that anyone gave a good one or not what we' were loking for.

But I'm pretty sure that is someone is looking for this issue, could try with this using telnet.

1. We open our terminal in linux.
2. Type: $telnet host port
Where host is the remote ip you are making a petition.
and port where the remote app is working, example if you are working in your local machine.

$telnet 120.0.0.1 8000

3.Telenet will display a prompt, even if it does not. We type: HEAD index.htm HTTP/1.0

This will make a petition with de HEAD method.

Hope this be useful, and a write because probably already is in the internet or books, but I don't found it.
I have to ask to my teacher.





Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16395
    
  23

Welcome to the JavaRanch, Ariel!

Yes, probably everyone in the thread has changed employers at least once since this thread was originally created. Except maybe Bill Brogden, who is an author of some repute.

Your solution is quite appropriate and I use it all the time.

The original Internet was more diverse than what we have today. It was primarily a lot of mainframes and minicomputers strung together. Some spoke ASCII, some spoke EBCDIC. Some had 8-bit bytes, some had other byte sizes.

To get them all communicating, the easiest way to work was to send and receive in text, not binary form. As long as you keep to a common set of characters, you don't have to worry about byte/word sizes, big or little ends, varying floating-point formats and the like. A character-set translation is a simple table lookup operation. Indeed, the IBM System/360 family actually has a low-level machine instruction that can do the translation.

So the older Internet utilities usually worked with text command and data formats and telnet was, in fact one of the prime ways of doing quick-and-dirty testing and debugging, since it didn't require creating and debugging special code. Or using specialized binary utilities that could be cumbersome and/or have their own problems and limitations.

HTTP is an obvious example, but the mail protocols also work that way.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
 
subject: How to call HEAD method ?