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

The POST method sends the encoded user information as a seperate message to page request. It is used to submit form data normally.

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 any extra path information associated with the URL the client sent?

A - Header.getPathInfo()

B - response.getPathInfo()

C - request.getPathInfo()

D - None of the above.

Answer : C

Explaination

request.getPathInfo() returns any extra path information associated with the URL the client sent when it made this request.

Q 5 - Which of the following code checks whether this request was made using a secure channel, such as HTTPS?

A - response.isSecure()

B - request.isSafe()

C - Header.isSecure()

D - None of the above.

Answer : B

Explaination

request.isSecure() returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Q 6 - Which of the following code can be used to clear any data that exists in the buffer as well as the status code and headers?

A - request.reset()

B - response.reset()

C - response.resetBuffer()

D - None of the above.

Answer : B

Explaination

response.reset() clears any data that exists in the buffer as well as the status code and headers.

Q 7 - Which of the following code can be used to set the content type for the body of the response?

A - request.setContentType(type)

B - response.setContentType(type)

C - header.setContentType(type)

D - None of the above.

Answer : B

Explaination

response.setContentType(type) sets the content type 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 language name in servlets?

A - response.getDisplayLanguage()

B - Locale.getDisplayLanguage()

C - request.getDisplayLanguage()

D - None of the above.

Answer : C

Explaination

request.getDisplayLanguage() returns a name for the locale's language that is appropriate for display to the user.

servlets-questions-answers.htm
Advertisements