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

A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

Q 2 - Which of the following method can be used to get the value of form parameter?

A - request.getParameter()

B - request.getParameterValues()

C - request.getParameterNames()

D - None of the above.

Answer : A

Explaination

You call request.getParameter() method to get the value of a form parameter.

Q 3 - Which of the following code retrieves the body of the request as binary data?

A - new InputStream()

B - response.getInputStream()

C - request.getInputStream()

D - None of the above.

Answer : C

Explaination

request.getInputStream() retrieves the body of the request as binary data using a ServletInputStream.

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

Q 7 - Which of the following is the correct order of filter life cycle phase methods?

A - init(), service(), destroy()

B - initialize(), service(), destroy()

C - init(), doFilter(), destroy()

D - init(), service(), delete()

Answer : A

Explaination

init() method is called by the web container to indicate to a filter that it is being placed into service. doFilter() method is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. destroy() method is called by the web container to indicate to a filter that it is being taken out of service.

Answer : A

Explaination

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

Q 10 - Which of the following code is used to get three-letter abbreviation for this locale's language in servlets?

A - response.getISO3Language()

B - Locale.getISO3Language()

C - request.getISO3Language()

D - None of the above.

Answer : C

Explaination

request.getISO3Language() returns a three-letter abbreviation for this locale's language.

servlets-questions-answers.htm
Advertisements