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

Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.

Q 2 - Which of the following method can be used to get the multiple values of a parameter like checkbox data?

A - request.getParameter()

B - request.getParameterValues()

C - request.getParameterNames()

D - None of the above.

Answer : B

Explaination

You call request.getParameterValues() method if the parameter appears more than once and returns multiple values, for example checkbox.

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

A - request.getSession()

B - response.getSession()

C - new Session()

D - None of the above.

Answer : A

Explaination

request.getSession() returns the current session associated with this request, or if the request does not have a session, creates one.

Q 4 - Which of the following code retrieves name and version of the protocol?

A - Header.getProtocol()

B - response.getProtocol()

C - request.getProtocol()

D - None of the above.

Answer : C

Explaination

request.getProtocol() returns the name and version of the protocol the request.

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 preferred buffer size for the body of the response?

A - response.setBufferSize(size)

B - request.setBufferSize(size)

C - header.setBufferSize(size)

D - None of the above.

Answer : A

Explaination

response.setBufferSize(size) sets the preferred buffer size for the body of the response.

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

A - request.getSession()

B - response.getSession();

C - new Session()

D - None of the above.

Answer : A

Explaination

request.getSession() is used to get a HTTP Session object in servlets.

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