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

Explaination

The init method is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. So, it is used for one-time initializations, just as with the init method of applets.

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 parameters in servlet?

A - request.getParameterNames()

B - response.getParameterNames()

C - Header.getParameterNames()

D - None of the above.

Answer : A

Explaination

request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in this request.

Q 4 - Which of the following code retrieves the value of a request parameter?

A - Header.getParameter(name)

B - response.getParameter(name)

C - request.getParameter(name)

D - None of the above.

Answer : C

Explaination

request.getParameter(name) returns the value of a request parameter as a String, or null if the parameter does not exist.

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.

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 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.

Answer : A

Explaination

response.addCookie(cookie) adds cookies in the HTTP response header.

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