- 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 - 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 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 Internet Protocol (IP) address of the client that sent the request?
Answer : A
Explaination
request.getRemoteAddr() returns the Internet Protocol (IP) address of the client that sent the request.
Q 5 - Which of the following code returns the port number on which this request was received?
Answer : B
Explaination
request.getServerPort() returns the port number on which this request was received.
Q 6 - Which of the following code can be used to redirect user to different url?
A - request.sendRedirect(location)
B - response.sendRedirect(location)
Answer : B
Explaination
response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.
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.message?
Answer : A
Explaination
javax.servlet.error.message attribute gives information exact error message which can be stored and analysed after storing in a java.lang.String data type.
Q 9 - Which of the following code is used to get session id of a HTTP Session object in servlets?
Answer : B
Explaination
session.getId() returns a string containing the unique identifier assigned to this session.
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