![Servlets Tutorial](/servlets/images/servlets-mini-logo.jpg)
- Servlets Tutorial
- 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 Useful Resources
- Servlets - Questions and Answers
- Servlets - Quick Guide
- Servlets - Useful Resources
- Servlets - Discussion
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.
![Questions and Answers](/images/questions_and_answers.png)
Q 1 - When doPost() method of servlet gets called?
A - A POST request results from an HTML form that specifically lists POST as the METHOD.
B - The service() method checks the HTTP request type as POST and calls doPost() method.
Answer : C
Explaination
A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() 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 body of the request as binary data?
Answer : C
Explaination
request.getInputStream() retrieves the body of the request as binary data using a ServletInputStream.
Q 4 - Which of the following code retrieves any extra path information associated with the URL the client sent?
Answer : C
Explaination
request.getPathInfo() returns any extra path information associated with the URL the client sent when it made this request.
Q 5 - Which of the following code encodes the specified URL by including the session ID in it?
Answer : A
Explaination
response.encodeURL(url) encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
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?
Answer : B
Explaination
response.reset() clears any data that exists in the buffer as well as the status code and headers.
Q 7 - Which of the following is the correct order of filter life cycle phase methods?
A - init(), service(), destroy()
B - initialize(), service(), destroy()
Answer : A
Explaination
init() method is called by the web container to indicate to a filter that it is being placed into service. doFilter() method is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. destroy() method is called by the web container to indicate to a filter that it is being taken out of service.
Q 8 - Which of the following is true about javax.servlet.error.message?
Answer : A
Explaination
javax.servlet.error.message attribute gives information exact error message which can be stored and analysed after storing in a java.lang.String data type.
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 get three-letter abbreviation for this locale's language in servlets?
Answer : C
Explaination
request.getISO3Language() returns a three-letter abbreviation for this locale's language.