- 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 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 - 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 is used to get names of the parameters in servlet?
A - request.getParameterNames()
B - response.getParameterNames()
Answer : A
Explaination
request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in this request.
Q 4 - Which of the following code retrieves the request header?
A - Header.getHeaderName(headerName)
B - response.getHeader(headerName)()
Answer : C
Explaination
request.getHeader(headerName) returns the value of the specified request header as a String.
Q 5 - Which of the following code retrieves session ID specified by the client?
A - request.getRequestedSessionId()
B - response.getRequestedSessionId()
Answer : A
Explaination
request.getRequestedSessionId() returns the session ID specified by the client.
Q 6 - Which of the following code can be used to clear the content of the underlying buffer in the response without clearing headers or status code.
Answer : C
Explaination
response.resetBuffer() clears the content of the underlying buffer in the response without clearing headers or status code.
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 init() method of filter?
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 filter 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 filter.
Q 9 - Which of the following code is used to get an attribute in a HTTP Session object in servlets?
A - session.getAttribute(name)
B - session.alterAttribute(name)
Answer : A
Explaination
session.getAttribute() returns the object bound with the specified name in this session, or null if no object is bound under the name.
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