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

Explaination

Each time the server receives a request for a servlet, the server spawns a new thread and calls service() method.

Answer : C

Explaination

The GET method sends the encoded user information appended to the page request. It is the defualt method to pass information from browser to web server.

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.

Q 4 - Which of the following code retrieves the MIME type of the body of the request?

A - new MimeType()

B - request.getContentType()

C - response.getContentType()

D - None of the above.

Answer : B

Explaination

request.getContentType() returns the MIME type of the body of the request, or null if the type is not known.

Q 5 - Which of the following code retrieves the part of this request's URL from the protocol name?

A - request.getRequestURI()

B - response.getRequestURI()

C - Header.getRequestURI()

D - None of the above.

Answer : A

Explaination

request.getRequestURI() returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Answer : B

Explaination

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

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 add an attribute in a HTTP Session object in servlets?

A - session.addAttribute(name,value)

B - session.setAttribute(name,value)

C - session.createAttribute(name,value)

D - None of the above.

Answer : B

Explaination

session.setAttribute() binds an object to this session, using the name specified.

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