
- Servlets - Home
- Servlets - Overview
- Servlets - Environment Setup
- Servlets - Life Cycle
- Servlets - Examples
- Servlets - Form Data
- Servlets - Client Request
- Servlets - Server Response
- Servlets - Http Codes
- Servlets - Writing Filters
- Servlets - Exceptions
- Servlets - Cookies Handling
- Servlets - Session Tracking
- Servlets - Database Access
- Servlets - File Uploading
- Servlets - Handling Date
- Servlets - Page Redirect
- Servlets - Hits Counter
- Servlets - Auto Refresh
- Servlets - Sending Email
- Servlets - Packaging
- Servlets - Debugging
- Servlets - Internationalization
- Servlets - Annotations
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.

Q 1 - When doGet() method of servlet gets called?
A - A GET request results from a normal request for a URL.
B - The service() method checks the HTTP request type as GET and calls doGet() method.
Answer : C
Explaination
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 - Which of the following method can be used to get the value of form parameter?
B - request.getParameterValues()
Answer : A
Explaination
You call request.getParameter() method to get the value of a form parameter.
Q 3 - Which of the following code retrieves the name of the authentication scheme?
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.
Q 4 - Which of the following code retrieves the context of the request?
Answer : B
Explaination
request.getContextPath() returns the portion of the request URI that indicates the context of the request.
Q 5 - Which of the following code indicates whether the response has been committed?
Answer : A
Explaination
response.isCommitted() returns a boolean indicating if the response has been committed.
Q 6 - Which of the following code can be used to add a header with the given name and integer value?
A - request.addHeader(name,value)
B - response.addIntHeader(name,value)
Answer : B
Explaination
response.addIntHeader(name,date) adds a response header with the given name and integer value.
Q 7 - Which of the following code can be used to set the character encoding for the body of the response?
A - response.setCharacterEncoding(charset)
B - request.setCharacterEncoding(charset)
Answer : A
Explaination
response.setCharacterEncoding(charset) sets the character encodinge for the body of the response.
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
Answer : D
Explaination
All of the above request attributes can be accessed by error-handling servlet.
Q 9 - Which of the following code sends a cookie in servlet?
A - response.addCookie(cookie);
B - response.sendCookie(cookie);
Answer : A
Explaination
response.addCookie(cookie) adds cookies in the HTTP response header.
Q 10 - Which of the following code is used to set the session timeout in servlets?
A - session.setMaxInactiveInterval(interval)
B - response.setMaxInactiveInterval(interval)
Answer : A
Explaination
You can call public void setMaxInactiveInterval(int interval) method of session to set the timeout for a session individually.