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.
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.
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.
A good workman is known by his tools.
Can you shoot lasers out of your eyes? Don't look at this tiny ad: