- 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 - Which of the following is true about destroy() method of servlet?
A - After the destroy() method is called, the servlet object is marked for garbage collection.
B - The servlet is terminated by calling the destroy() method.
Answer : C
Explaination
The servlet is terminated by calling the destroy() method. After the destroy() method is called, the servlet object is marked for garbage collection.
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 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 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 write a cookie?
Answer : B
Explaination
response.addCookie(cookie) adds the specified cookie to the response and can be used to write a cookie.
Q 7 - Which of the following code can be used to set the status code of the response?
A - response.setStatus(statusCode)
B - request..setStatus(statusCode)
Answer : A
Explaination
response.setLocale(locale) sets the status code 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.
Answer : B
Explaination
HTTP is a stateless protocol which means each time a client retrieves a Web page, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.
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.
To Continue Learning Please Login
Login with Google