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 : D

Explaination

The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client. Each time the server receives a request for a servlet, the server spawns a new thread and calls service. 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 code is used to set content type of a page to be serviced using servlet?

A - response.setContentType()

B - request.setContentType()

C - writer.setContentType()

D - None of the above.

Answer : A

Explaination

You call response.setContentType() method to set content type of a page to be serviced using servlet.

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

A - response.getWriter()

B - request.getWriter()

C - new PrintWriter()

D - None of the above.

Answer : A

Explaination

You call response.getWriter() method to get PrintWriter object in servlet.

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 returns the port number on which this request was received?

A - response.getServerPort()

B - request.getServerPort()

C - Header.getServerPort()

D - None of the above.

Answer : B

Explaination

request.getServerPort() returns the port number on which this request was received.

Q 6 - Which of the following code can be used to force any content in the buffer to be written to the client?

A - request.flushBuffer()

B - response.flush()

C - response.flushBuffer()

D - None of the above.

Answer : C

Explaination

response.flushBuffer() forces any content in the buffer to be written to the client.

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.

Q 9 - Which of the following way can be used to keep track of previous client request?

A - Using cookies.

B - Using hidden form fields.

C - Using URL rewriting.

D - All of the above.

Answer : D

Explaination

All of the above can be used to keep track of previous client request.

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