- 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.
Q 1 - Which of the following is true about service() method of servlet?
Answer : D
Explaination
The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client. Each time the server receives a request for a servlet, the server spawns a new thread and calls service. 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 code is used to set content type of a page to be serviced using servlet?
Answer : A
Explaination
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?
Answer : A
Explaination
You call response.getWriter() method to get PrintWriter object in servlet.
Q 4 - Which of the following code retrieves name and version of the protocol?
Answer : C
Explaination
request.getProtocol() returns the name and version of the protocol the request.
Q 5 - Which of the following code returns the port number on which this request was received?
Answer : B
Explaination
request.getServerPort() returns the port number on which this request was received.
Q 6 - Which of the following code can be used to force any content in the buffer to be written to the client?
Answer : C
Explaination
response.flushBuffer() forces any content in the buffer to be written to the client.
Q 7 - Which of the following code can be used to set the locale of the response?
Answer : B
Explaination
response.setLocale(locale) sets the locale of the response.
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 way can be used to keep track of previous client request?
Answer : D
Explaination
All of the above can be used to keep track of previous client request.
Q 10 - Which of the following code is used to get three-letter abbreviation for this locale's country in servlets?
Answer : A
Explaination
request.getISO3Country() returns a three-letter abbreviation for this locale's country.
To Continue Learning Please Login
Login with Google