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 - What are Servlets?
Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
Q 2 - Which of the following code is used to set content type of a page to be serviced using servlet?
You call response.setContentType() method to set content type of a page to be serviced using servlet.
Q 3 - Which of the following code is used to get PrintWriter object in servlet?
You call response.getWriter() method to get PrintWriter object in servlet.
Q 4 - Which of the following code retrieves the request header?
request.getHeader(headerName) returns the value of the specified request header as a String.
Q 5 - Which of the following code retrieves the login of the user making this request?
request.getRemoteUser() returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
Q 6 - Which of the following code can be used to redirect user to different url?
response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.
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 - Which of the following is true about init() method of filter?
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.
Q 9 - Which of the following code is used to delete a HTTP Session object in servlets?
session.invalidate() invalidates this session and unbinds any objects bound to it.
Q 10 - Which of the following code is used to get language code in servlets?
request.getLanguage() returns the language code in lower case for this locale in ISO 639 format.