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

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 retrieves the name of the authentication scheme?

A - new AuthType()

B - response.getAuthType()

C - request.getAuthType()

D - None of the above.

Answer : C

Explaination

request.getAuthType() returns the name of the authentication scheme used to protect the servlet, for example, BASIC or SSL or null if the JSP was not protected.

Answer : C

Explaination

request.getHeader(headerName) returns the value of the specified request header as a String.

Q 5 - Which of the following code checks whether this request was made using a secure channel, such as HTTPS?

A - response.isSecure()

B - request.isSafe()

C - Header.isSecure()

D - None of the above.

Answer : B

Explaination

request.isSecure() returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Answer : B

Explaination

response.addCookie(cookie) adds the specified cookie to the response and can be used to write a cookie.

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.

Answer : C

Explaination

The init method is designed to be called only once. It is called when the filter is first created, and not called again for each user request. It simply creates or loads some data that will be used throughout the life of the filter.

Answer : A

Explaination

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

Answer : A

Explaination

You can call public void setMaxInactiveInterval(int interval) method of session to set the timeout for a session individually.


servlets-questions-answers.htm

Advertisements