Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pg. 143 Head First book

 
Jayanthi Mani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I just had a doubt about question no:8 on pg. 143.

"Which methods are used by a servlet to handle form data from a client?"(Choose all that apply)

A. HttpServlet.doHead()
B. HttpServlet.doPost()
C. HttpServlet.doForm()
D. ServletRequest.doGet()
E. ServletRequest.doPost()
F. ServletRequest.doForm()

The answer is given as option "B".

Shouldn't the answer be option "D" (ServletRequest.doGet) b'cos by default a form is said to call the doGet() method in the servlet(when the 'submit' is clicked)?

Can somebody please explain why the answer is stated as "B"?
Thanks,
Jayanthi.
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question probably should have been "Which method should be....."

Because for to process Form data which has many fields, it would be more convinient to process it to POST method as GET involves a restriction of 255 characters.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jayanthi Mani:
Hello,
I just had a doubt about question no:8 on pg. 143.

"Which methods are used by a servlet to handle form data from a client?"(Choose all that apply)

A. HttpServlet.doHead()
B. HttpServlet.doPost()
C. HttpServlet.doForm()
D. ServletRequest.doGet()
E. ServletRequest.doPost()
F. ServletRequest.doForm()

The answer is given as option "B".

Shouldn't the answer be option "D" (ServletRequest.doGet) b'cos by default a form is said to call the doGet() method in the servlet(when the 'submit' is clicked)?

Can somebody please explain why the answer is stated as "B"?
Thanks,
Jayanthi.


Jayanthi,

The 'ServletRequest' does not have doXXXX methods, so 'D' option is wrong



regards,
MZ
 
Jayanthi Mani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Mikalai! That explains it better now....
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The way the mock questions are phrased makes it tougher than the real exams. Although the question told us to choose all that apply & methods had an 's', its really meant to test our understanding & whether we read the APIs.

In the real exams, we'll be told exactly how many correct answers they would be. This make our life easier. But if you could get pass those trick questions in the mock, I guess you're pretty safe in the real exams.

HTH.

 
Icaro Dourado
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I know it is an old topic but since it is the only one I found on the forum that address to my following question...


The thing is, if we strictly think about the possibility to or not to handle 'form data' in a servlet, I see nothing wrong about letter A, which states doHead() from HttpServletRequest. I mean, isn't possible to get parameters and then process them when we are handling a doHead() ? If so, for me both A and B seem to be right answers.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Icaro,

The thing is, if we strictly think about the possibility to or not to handle 'form data' in a servlet, I see nothing wrong about letter A, which states doHead() from HttpServletRequest. I mean, isn't possible to get parameters and then process them when we are handling a doHead() ?

You can only submit form data with the method "get" and "post", like:

See also w3schools

It won't accept other methods like "head", that is why A is not correct.

Regards,
Frits
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume that Option G : HttpServlet.doGet() is given as a choice. In that case, the answer will be both Option B and G [OR] just Option B ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic