- 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 init() method of servlet gets called?
A - The init() method is called when the servlet is first created.
B - The init() method is called whenever the servlet is invoked.
Answer : A
Explaination
The init method is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. So, it is used for one-time initializations, just as with the init method of applets.
Q 2 - Which of the following code is used to set content type of a page to be serviced using servlet?
Answer : A
Explaination
You call response.setContentType() method to set content type of a page to be serviced using servlet.
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 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 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 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 is true about filters?
Answer : C
Explaination
Servlet Filters are Java classes that can be used to intercept requests from a client before they access a resource at back end and to manipulate responses from server before they are sent back to the client.
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 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 country/region name in servlets?
A - request.getDisplayCountry()
B - Locale.getDisplayCountry()
Answer : A
Explaination
request.getDisplayCountry() returns the country/region name for the locale's country that is appropriate for display to the user.
To Continue Learning Please Login
Login with Google