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

Q 2 - What is javax.servlet.http.HttpServlet?

A - interface

B - abstract class

C - concreate class

D - None of the above.

Answer : B

Explaination

javax.servlet.http.HttpServlet is an abstract class.

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 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 encodes the specified URL by including the session ID in it?

A - response.encodeURL(url)

B - request.encodeURL(url)

C - Header.encodeURL(url)

D - None of the above.

Answer : A

Explaination

response.encodeURL(url) encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.

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.

Answer : A

Explaination

The init method is designed to be called only once. It is called by the web container to indicate to a filter that it is being placed into service.

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

A - session.removeAttribute(name)

B - session.alterAttribute(name)

C - session.updateAttribute(name)

D - None of the above.

Answer : A

Explaination

session.removeAttribute() removes the object bound with the specified name from this session.

servlets-questions-answers.htm
Advertisements