- 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 - 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 names of the attributes in servlet?
A - response.getAttributeNames()
B - request.getAttributeNames()
Answer : B
Explaination
request.getAttributeNames() returns an enumeration containing the names of the attributes available to this request.
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 clear any data that exists in the buffer as well as the status code and headers?
Answer : B
Explaination
response.reset() clears any data that exists in the buffer as well as the status code and headers.
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.exception_type?
Answer : B
Explaination
javax.servlet.error.exception_type attribute gives information about exception type which can be stored and analysed after storing in a java.lang.Class data type.
Q 9 - Which of the following code is used to update an attribute in a HTTP Session object in servlets?
A - session.setAttribute(name,value)
B - session.alterAttribute(name,value)
Answer : A
Explaination
session.setAttribute() binds an object to this session, using the name specified.
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.
To Continue Learning Please Login
Login with Google