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

A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

Answer : C

Explaination

The servlet is terminated by calling the destroy() method. After the destroy() method is called, the servlet object is marked for garbage collection.

Q 3 - Which of the following code is used to get locale in servlet?

A - request.getlocale()

B - response.getLocale()

C - new Locale()

D - None of the above.

Answer : A

Explaination

request.getlocale() returns the preferred Locale that the client will accept content in, based on the Accept-Language header.

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 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 redirect user to different url?

A - request.sendRedirect(location)

B - response.sendRedirect(location)

C - header.sendRedirect(location)

D - None of the above.

Answer : B

Explaination

response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.

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.

Answer : A

Explaination

Create cookie using new operator on Cookie class.

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

A - session.getAttribute(name)

B - session.alterAttribute(name)

C - session.updateAttribute(name)

D - None of the above.

Answer : A

Explaination

session.getAttribute() returns the object bound with the specified name in this session, or null if no object is bound under the name.

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