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

Explaination

The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client. Each time the server receives a request for a servlet, the server spawns a new thread and calls service. 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 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 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 force any content in the buffer to be written to the client?

A - request.flushBuffer()

B - response.flush()

C - response.flushBuffer()

D - None of the above.

Answer : C

Explaination

response.flushBuffer() forces any content in the buffer to be written to the client.

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 8 - Which of the following request attributes that an error-handling servlet can access to analyse the nature of error/exception?

A - javax.servlet.error.status_code

B - javax.servlet.error.exception_type

C - javax.servlet.error.message

D - All of the above.

Answer : D

Explaination

All of the above request attributes can be accessed by error-handling servlet.

Q 9 - Does server automatically keep any record of previous client request?

A - true

B - false

Answer : B

Explaination

HTTP is a stateless protocol which means each time a client retrieves a Web page, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.

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

A - request.getISO3Country()

B - Locale.getISO3Country()

C - response.getISO3Country()

D - None of the above.

Answer : A

Explaination

request.getISO3Country() returns a three-letter abbreviation for this locale's country.

servlets-questions-answers.htm
Advertisements