• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doHead() internally calls doGet()

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is incorrect. Wat do you say?
Les discuss this on some messenger if you will.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic