- 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 - When service() method of servlet gets called?
A - The service() method is called when the servlet is first created.
B - The service() method is called whenever the servlet is invoked.
Answer : B
Explaination
Each time the server receives a request for a servlet, the server spawns a new thread and calls service() method.
Q 2 - What is javax.servlet.Servlet?
Answer : A
Explaination
javax.servlet.Servlet is an interface.
Q 3 - Which of the following code is used to get session in servlet?
Answer : A
Explaination
request.getSession() returns the current session associated with this request, or if the request does not have a session, creates one.
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 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 send an error response to the client using the specified status code and error message?
A - request.sendError(statusCode,message)
B - response.sendError(statusCode,message)
Answer : B
Explaination
response.sendError(statusCode,message) sends an error response to the client using the specified status code and error message.
Q 7 - Which of the following code can be used to set the character encoding for the body of the response?
A - response.setCharacterEncoding(charset)
B - request.setCharacterEncoding(charset)
Answer : A
Explaination
response.setCharacterEncoding(charset) sets the character encodinge for the body of the response.
Q 8 - Which element of web.xml is used to specify the error handler in servlets?
Answer : A
Explaination
You would have to use the error-page element in web.xml to specify the invocation of servlets in response to certain exceptions or HTTP status codes.
Q 9 - Which of the following code is used to get a HTTP Session object in servlets?
Answer : A
Explaination
request.getSession() is used to get a HTTP Session object in servlets.
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