
- 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 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 retrieves the body of the request as binary data?
Answer : C
Explaination
request.getInputStream() retrieves the body of the request as binary data using a ServletInputStream.
Q 4 - Which of the following code retrieves name and version of the protocol?
Answer : C
Explaination
request.getProtocol() returns the name and version of the protocol the request.
Q 5 - Which of the following code retrieves the fully qualified name of the client making this request?
Answer : A
Explaination
request.getRemoteHost() returns the fully qualified name of the client that sent the request.
Q 6 - Which of the following code can be used to force any content in the buffer to be written to the client?
Answer : C
Explaination
response.flushBuffer() forces any content in the buffer to be written to the client.
Q 7 - Which of the following code can be used to set the content type for the body of the response?
A - request.setContentType(type)
B - response.setContentType(type)
Answer : B
Explaination
response.setContentType(type) sets the content type 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 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 set the session timeout in servlets?
A - session.setMaxInactiveInterval(interval)
B - response.setMaxInactiveInterval(interval)
Answer : A
Explaination
You can call public void setMaxInactiveInterval(int interval) method of session to set the timeout for a session individually.