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

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 character encoding used in the body of this request?

A - new CharacterEncoding()

B - response.getCharacterEncoding()

C - request.getCharacterEncoding()

D - None of the above.

Answer : C

Explaination

request.getCharacterEncoding() returns the name of the character encoding used in the body of this request.

Q 5 - Which of the following code retrieves the fully qualified name of the client making this request?

A - request.getRemoteHost()

B - response.getRemoteHost()

C - Header.getRemoteHost()

D - None of the above.

Answer : A

Explaination

request.getRemoteHost() returns the fully qualified name of the client that sent the request.

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.

Answer : C

Explaination

Servlet Filters are Java classes that can be used to intercept requests from a client before they access a resource at back end and to manipulate responses from server before they are sent back to the client.

Q 8 - Which of the following request attributes that an error-handling servlet can access to analyse the nature of error/exception?

A - javax.servlet.error.status_code

B - javax.servlet.error.exception_type

C - javax.servlet.error.message

D - All of the above.

Answer : D

Explaination

All of the above request attributes can be accessed by error-handling servlet.

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

A - session.setAttribute(name,value)

B - session.alterAttribute(name,value)

C - session.updateAttribute(name,value)

D - None of the above.

Answer : A

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