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

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 names of the attributes in servlet?

A - response.getAttributeNames()

B - request.getAttributeNames()

C - Header.getAttributeNames()

D - None of the above.

Answer : B

Explaination

request.getAttributeNames() returns an enumeration containing the names of the attributes available to 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 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.

Answer : A

Explaination

response.addDateHeader(name,date) adds a response header with the given name and date-value.

Answer : A

Explaination

The init method is designed to be called only once. It is called by the web container to indicate to a filter that it is being placed into service.

Answer : A

Explaination

Create cookie using new operator on Cookie class.

Q 9 - Does server automatically keep any record of previous client request?

A - true

B - false

Answer : B

Explaination

HTTP is a stateless protocol which means each time a client retrieves a Web page, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.

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

Explaination

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


servlets-questions-answers.htm

Advertisements