• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Whizlabs Question

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 was doing a question on Whizlabs Preparation Kit and it showed the following question:-

The processServlet implements service(), doGet(), and doPost() methods and is mapped to the URL http://server/shopping/ProcessServlet. Which method is invoked when a user enters the above URL in the browser's address bar?

A. doPost()
B. doGet()
C. Depends on the browser vendor.
D. Cannot be determined based on the given information.

Answer: B

Now in the explanation, it gives the following:-

Choice B is the correct answer.

The browser sends a GET request when

A. User clicks a hyperlink.
B. the "method" attribute of the HTMl FORM element is ""GET" or missing or when it contains invalid values and a submit is made
C. Using browser's address field to submit a request

Hence choice B is correct while choices A and C are incorrect.

This behavior is a standard behavior and does not depend on a particular implementation. Hence choice D id also incorrect.

I think however, that answer D is correct because of the following code that I tested and printed Hello.

This was my web.xml:-

Did i misunderstand the question?
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question would be better if it did not state that the service method were implemented.

The service method of HttpServlet by default will send GET requests to the doGet method and POST requests to doPost. You've overridden the service method to always cause the doPost method to receive all requests.
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic