Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Whizlabs Question  RSS feed

Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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?
Marc Peabody
pie sneak
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!