- 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 - When init() method of servlet gets called?
A - The init() method is called when the servlet is first created.
B - The init() method is called whenever the servlet is invoked.
Answer : A
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. So, it is used for one-time initializations, just as with the init method of applets.
Q 2 - Which of the following method can be used to get the multiple values of a parameter like checkbox data?
B - request.getParameterValues()
Answer : B
Explaination
You call request.getParameterValues() method if the parameter appears more than once and returns multiple values, for example checkbox.
Q 3 - Which of the following code is used to get locale in servlet?
Answer : A
Explaination
request.getlocale() returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
Q 4 - Which of the following code retrieves the character encoding used in the body of this request?
B - response.getCharacterEncoding()
Answer : C
Explaination
request.getCharacterEncoding() returns the name of the character encoding used in the body of this request.
Q 5 - Which of the following code encodes the specified URL for use in the sendRedirect method?
A - response.encodeRedirectURL(url)
B - request.encodeRedirectURL(url)
Answer : A
Explaination
response.encodeRedirectURL(url) encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
Q 6 - Which of the following code can be used to send an error response to the client using the specified status code and clearing the buffer.
A - request.sendError(statusCode)
B - response.sendError(statusCode)
Answer : B
Explaination
response.sendError(statusCode) sends an error response to the client using the specified status code and clearing the buffer.
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 of the following is true about javax.servlet.error.request_uri?
Answer : D
Explaination
javax.servlet.error.request_uri attribute gives information about URL calling the servlet and it can be stored and analysed after storing in a java.lang.String data type.
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 country/region code in servlets?
Answer : A
Explaination
request.getCountry() returns the country/region code in upper case for this locale in ISO 3166 2-letter format.
