
- 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
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 the correct order of servlet life cycle phase methods?
A - init(), service(), destroy()
B - initialize(), service(), destroy()
Answer : A
Explaination
The servlet is initialized by calling the init () method. The servlet calls service() method to process a client's request. The servlet is terminated by calling the destroy() method.
Q 2 - Which of the following is true about HTTP Post method?
A - The POST method sends the encoded user information as a seperate message to page request.
Answer : C
Explaination
The POST method sends the encoded user information as a seperate message to page request. It is used to submit form data normally.
Q 3 - Which of the following code retrieves the name of the authentication scheme?
Answer : C
Explaination
request.getAuthType() returns the name of the authentication scheme used to protect the servlet, for example, BASIC or SSL or null if the JSP was not protected.
Q 4 - Which of the following code retrieves any extra path information associated with the URL the client sent?
Answer : C
Explaination
request.getPathInfo() returns any extra path information associated with the URL the client sent when it made this request.
Q 5 - Which of the following code encodes the specified URL by including the session ID in it?
Answer : A
Explaination
response.encodeURL(url) encodes the specified URL by including the session ID in it, 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 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 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 set auto refresh of a page after 5 seconds?
A - session.setIntHeader("Refresh", 5)
B - response.setIntHeader("Refresh", 5)
Answer : B
Explaination
response.setIntHeader("Refresh", 5) sets refresh, autoload time as 5 seconds.