Servlets - Online Quiz



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

Explaination

The init method is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. It simply creates or loads some data that will be used throughout the life of the servlet.

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

Explaination

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

Explaination

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

Answer : C

Explaination

request.getHeader(headerName) returns the value of the specified request header as a String.

Q 5 - Which of the following code retrieves session ID specified by the client?

A - request.getRequestedSessionId()

B - response.getRequestedSessionId()

C - Header.getRequestedSessionId()

D - None of the above.

Answer : A

Explaination

request.getRequestedSessionId() returns the session ID specified by the client.

Q 6 - Which of the following code can be used to clear the content of the underlying buffer in the response without clearing headers or status code.

A - request.reset()

B - response.reset()

C - response.resetBuffer()

D - None of the above.

Answer : C

Explaination

response.resetBuffer() clears the content of the underlying buffer in the response without clearing headers or status code.

Q 7 - Which of the following code can be used to set the locale of the response?

A - request.setLocale(locale)

B - response.setLocale(locale)

C - header.setLocale(locale)

D - None of the above.

Answer : B

Explaination

response.setLocale(locale) sets the locale of the response.

Answer : C

Explaination

The init method is designed to be called only once. It is called when the filter is first created, and not called again for each user request. It simply creates or loads some data that will be used throughout the life of the filter.

Q 9 - Which of the following code is used to get an attribute in a HTTP Session object in servlets?

A - session.getAttribute(name)

B - session.alterAttribute(name)

C - session.updateAttribute(name)

D - None of the above.

Answer : A

Explaination

session.getAttribute() returns the object bound with the specified name in this session, or null if no object is bound under the name.

Q 10 - Which of the following code is used to get three-letter abbreviation for this locale's country in servlets?

A - request.getISO3Country()

B - Locale.getISO3Country()

C - response.getISO3Country()

D - None of the above.

Answer : A

Explaination

request.getISO3Country() returns a three-letter abbreviation for this locale's country.

servlets-questions-answers.htm
Advertisements