• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doHead() internally calls doGet()

 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have overridden doGet() only in my servlet and a request comes for doHead() then does it throw an error or executes doGet()?

Given the following servlet code, identify what will happen when a HEAD request is made to the servlet's URL.

[CODE:JAVA NUM]
public class TestHeadRequest extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
System.out.println("In TestHeadRequest");
PrintWriter out = response.getWriter();
out.write("Method Executed");
}
}
[/CODE:JAVA]

Possible Answer(s)
- "In TestHeadRequest" is output to the console.
- "In TestHeadRequest" is output to the console and "Method Executed" is returned in the response body.
- Nothing is output to the console or returned to the response body.
- An HTTP response code 405 (Method Not Allowed) is returned to the requester.
- Line 16 does not execute.

Correct Answers "In TestHeadRequest" is output to the console.
 
Kejal Shah
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is incorrect. Wat do you say?
Les discuss this on some messenger if you will.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The question related to this is how to pass the HEAD request to the server. I had tried using HTTP FORM method attribute. But it takes only GET and POST for all the other options like PUT, HEAD it is executing doGet() method.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic