- 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 - What are Servlets?
A - Java Servlets are programs that run on a Web or Application server.
Answer : C
Explaination
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 is true about destroy() method of servlet?
A - After the destroy() method is called, the servlet object is marked for garbage collection.
B - The servlet is terminated by calling the destroy() method.
Answer : C
Explaination
The servlet is terminated by calling the destroy() method. After the destroy() method is called, the servlet object is marked for garbage collection.
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 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 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 send an error response to the client using the specified status code and error message?
A - request.sendError(statusCode,message)
B - response.sendError(statusCode,message)
Answer : B
Explaination
response.sendError(statusCode,message) sends an error response to the client using the specified status code and error message.
Q 7 - Which of the following code can be used to set the preferred buffer size for the body of the response?
A - response.setBufferSize(size)
B - request.setBufferSize(size)
Answer : A
Explaination
response.setBufferSize(size) sets the preferred buffer size for the body of the response.
Q 8 - Which element of web.xml is used to specify the error handler in servlets?
Answer : A
Explaination
You would have to use the error-page element in web.xml to specify the invocation of servlets in response to certain exceptions or HTTP status codes.
Q 9 - Which of the following code is used to get session id of a HTTP Session object in servlets?
Answer : B
Explaination
session.getId() returns a string containing the unique identifier assigned to this session.
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.
