- 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 - 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 is true about HTTP Get method?
A - The GET method sends the encoded user information appended to the page request.
B - The GET method is the defualt method to pass information from browser to web server.
Answer : C
Explaination
The GET method sends the encoded user information appended to the page request. It is the defualt method to pass information from browser to web server.
Q 3 - Which of the following code is used to get names of the parameters in servlet?
A - request.getParameterNames()
B - response.getParameterNames()
Answer : A
Explaination
request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in this request.
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 indicates whether the response has been committed?
Answer : A
Explaination
response.isCommitted() returns a boolean indicating if the response has been committed.
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 locale of the response?
Answer : B
Explaination
response.setLocale(locale) sets the locale of the response.
Q 8 - How to create a cookie in servlet?
B - Use request.getCookie() method
Answer : A
Explaination
Create cookie using new operator on Cookie class.
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 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.
