Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

mock question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem

Which method(s) of RegisterServlet will be called when the user clicks on "Submit" button for the following form. Assume that RegisterServlet does not override the service() method of HttpServlet class.
<html>
<body>
<form action="/RegisterServlet">
<input type="text" name="method" value="POST">
<input type="text" name="name">
<input type="password" name="password">
<input type="submit" value="POST">
</form>
</body>
</html>



Options

Select 1 correct option.

1 servicePost(HttpRequest, HttpResponse);

2 doPOST(HttpRequest, HttpResponse);

3 doPost(HttpRequest, HttpResponse);

4 None of the above.

I think doGet() will be called. so answer should be 4 but answer is 3...some one too feels the same???/
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When you use a HTTP form to submit info to server, doPost() must be called.
doGet() is called when you either type URL in browser address bar, or click a hyperlink, or submit HTTP form with method="GET".
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, GET is the default method used on an HTML form. Since it isn't specified, This will cause the doGet method of the Servlet to be called. The other instances of the word POST in the text element and the submit element have to do with what those elements display and not what method will be used. so, the answer would have to be 4.
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would agree with Carl. The "POST" mentioned in other places do not mean anything.
The first textbox will be named "method" and will have a default value "POST" showing on the textbox.
The second textbox will be named "name" and will not have anything by default.
The password textbox will be named "password" and will not show anything.
The submit button will contain the string "POST" in its button. Since a name is not specified, I don't know what name it will choose.
The HTTP spec. says that if there is no method attribute in a FORM element, then GET will be used by default.
As there is not doGet() or service() in the answers, I would go with 4.
 
His brain is the size of a cherry pit! About the size of this ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic