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.
Q 1 - Which of the following is the correct order of servlet life cycle phase methods?
The servlet is initialized by calling the init () method. The servlet calls service() method to process a client's request. The servlet is terminated by calling the destroy() method.
Q 2 - What is javax.servlet.Servlet?
javax.servlet.Servlet is an interface.
Q 3 - Which of the following code is used to get session in servlet?
request.getSession() returns the current session associated with this request, or if the request does not have a session, creates one.
Q 4 - Which of the following code retrieves the query string that is contained in the request URL after the path?
request.getQueryString() returns the query string that is contained in the request URL after the path.
Q 5 - Which of the following code retrieves session ID specified by the client?
request.getRequestedSessionId() returns the session ID specified by the client.
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?
response.reset() clears any data that exists in the buffer as well as the status code and headers.
Q 7 - Which of the following code can be used to set the content type for the body of the response?
response.setContentType(type) sets the content type for the body of the response.
Q 8 - When destroy() method of filter gets called?
The destroy() method is called only once at the end of the life cycle of a filter.
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 set the session timeout in servlets?
You can call public void setMaxInactiveInterval(int interval) method of session to set the timeout for a session individually.