Servlets Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to Servlets Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Answer : C

Explanation

A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

Q 2 - Which of the following method can be used to get the value of form parameter?

A - request.getParameter()

B - request.getParameterValues()

C - request.getParameterNames()

D - None of the above.

Answer : A

Explanation

You call request.getParameter() method to get the value of a form parameter.

Q 3 - Which of the following code is used to get names of the parameters in servlet?

A - request.getParameterNames()

B - response.getParameterNames()

C - Header.getParameterNames()

D - None of the above.

Answer : A

Explanation

request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in this request.

Q 4 - Which of the following code retrieves any extra path information associated with the URL the client sent?

A - Header.getPathInfo()

B - response.getPathInfo()

C - request.getPathInfo()

D - None of the above.

Answer : C

Explanation

request.getPathInfo() returns any extra path information associated with the URL the client sent when it made this request.

Q 5 - Which of the following code indicates whether the response has been committed?

A - response.isCommitted()

B - request.isCommitted()

C - Header.isCommitted()

D - None of the above.

Answer : A

Explanation

response.isCommitted() returns a boolean indicating if the response has been committed.

Answer : B

Explanation

response.addCookie(cookie) adds the specified cookie to the response and can be used to write a cookie.

Answer : D

Explanation

All of the above filters are suggested by the servlet specifications.

Answer : B

Explanation

You can use setMaxAge to delete a cookie by setting is zero.

Q 10 - Which of the following code is used to get language code in servlets?

A - response.getLanguage()

B - Locale.getLanguage()

C - request.getLanguage()

D - None of the above.

Answer : C

Explanation

request.getLanguage() returns the language code in lower case for this locale in ISO 639 format.


servlets-questions-answers.htm

Advertisements