• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dohead

 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per java API
GET request also automatically supports an HTTP HEAD
request


1.even if we don't override doHead method can we make head request.
2. If we override doHead method and make head request wich method will be called doHead or doGet
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually GET = HEAD + message Body

If you override the doHead method and call the doHead method, then by simple java rules, it must call doHead( ) method.
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sunny,
So waht about

1.even if we don't override doHead method can we make head request.
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, because this method is implemented in the HttpServlet class (doHead)

Therefore if your servlet extends HttpServlet class (which is an abstract class) the HEAD request will be handled by the doHead() which is defined in the superclass (HttpServlet).

Regards,
Krzysiek
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've checked the HttpServlet implementation and it looks like the doHead() method doesn't do anything useful by default:

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks very useful to me; in fact, it's exactly what it should be doing, which is to execute a GET but to return an empty response body.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slightly off-topic: so are the defalut implementations of doGet and doPost the only methods that throw a NotSupportedException? Or doPut and doDelete also?

Where can you check the source code of HttpServlet?
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just search for "HttpServlet source" You may find it here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic