File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "mock question" Watch "mock question" New topic
Author

mock question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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???/
tony lee
Ranch Hand

Joined: Jan 21, 2002
Posts: 52
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".


SCJP2, SCWCD
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
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.


Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
 
 
subject: mock question
 
Threads others viewed
getParameter
in which method shuld i use at the servlet code for request
Form Authentication does not work TomCat 5.5?
regarding servlet mapping
doubt from jdiscuss
developer file tools