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 - When doGet() method of servlet gets called?
A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() 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 - What is javax.servlet.http.HttpServlet?
javax.servlet.http.HttpServlet is an abstract class.
Q 3 - Which of the following code retrieves the name of the authentication scheme?
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.
Q 4 - Which of the following code retrieves the character encoding used in the body of this request?
request.getCharacterEncoding() returns the name of the character encoding used in the body of this request.
Q 5 - Which of the following code returns the port number on which this request was received?
request.getServerPort() returns the port number on which this request was received.
Q 6 - Which of the following code can be used to add a date header?
response.addDateHeader(name,date) adds a response header with the given name and date-value.
Q 7 - Which of the following code can be used to set the character encoding for the body of the response?
response.setCharacterEncoding(charset) sets the character encodinge 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 add an attribute in a HTTP Session object in servlets?
session.setAttribute() binds an object to this session, using the name specified.
Q 10 - Which of the following code is used to get locale in servlets?
request.getLocale() returns Local object.