- 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 - Which of the following is true about init() method of servlet?
B - The init() method is not called again and again for each user request.
Answer : C
Explaination
The init method is designed to be called only once. It is called when the servlet 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 servlet.
Q 2 - When destroy() method of servlet gets called?
A - The destroy() method is called only once at the end of the life cycle of a servlet.
B - The destroy() method is called after the servlet has executed service method.
Answer : A
Explaination
The destroy() method is called only once at the end of the life cycle of a servlet.
Q 3 - Which of the following code is used to get cookies in servlet?
Answer : B
Explaination
request.getCookies() returns an array containing all of the Cookie objects the client sent with this request.
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 redirect user to different url?
A - request.sendRedirect(location)
B - response.sendRedirect(location)
Answer : B
Explaination
response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.
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 - When destroy() method of filter gets called?
A - The destroy() method is called only once at the end of the life cycle of a filter.
B - The destroy() method is called after the filter has executed doFilter method.
Answer : A
Explaination
The destroy() method is called only once at the end of the life cycle of a filter.
Q 9 - Which of the following code is used to add an attribute in a HTTP Session object in servlets?
A - session.addAttribute(name,value)
B - session.setAttribute(name,value)
Answer : B
Explaination
session.setAttribute() binds an object to this session, using the name specified.
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.
