- 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 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 is used to get cookies in servlet?
Answer : B
Explaination
request.getCookies() returns an array containing all of the Cookie objects the client sent with this request.
Q 4 - Which of the following code retrieves the query string that is contained in the request URL after the path?
Answer : C
Explaination
request.getQueryString() returns the query string that is contained in the request URL after the path.
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 locale of the response?
Answer : B
Explaination
response.setLocale(locale) sets the locale of the response.
Q 8 - When destroy() method of filter gets called?
A - The destroy() method is called only once at the end of the life cycle of a filter.
B - The destroy() method is called after the filter has executed doFilter method.
Answer : A
Explaination
The destroy() method is called only once at the end of the life cycle of a filter.
Q 9 - Which of the following way can be used to keep track of previous client request?
Answer : D
Explaination
All of the above can be used to keep track of previous client request.
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.
To Continue Learning Please Login
Login with Google