- 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 - Which of the following is true about init() method of servlet?
B - The init() method is not called again and again for each user request.
Answer : C
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. It simply creates or loads some data that will be used throughout the life of the servlet.
Q 2 - What is javax.servlet.http.HttpServlet?
Answer : B
Explaination
javax.servlet.http.HttpServlet is an abstract class.
Q 3 - Which of the following code is used to get session in servlet?
Answer : A
Explaination
request.getSession() returns the current session associated with this request, or if the request does not have a session, creates one.
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 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 character encoding for the body of the response?
A - response.setCharacterEncoding(charset)
B - request.setCharacterEncoding(charset)
Answer : A
Explaination
response.setCharacterEncoding(charset) sets the character encodinge for the body of the response.
Q 8 - Which of the following is true about javax.servlet.error.exception_type?
Answer : B
Explaination
javax.servlet.error.exception_type attribute gives information about exception type which can be stored and analysed after storing in a java.lang.Class data type.
Q 9 - Which of the following code delete a cookie in servlet?
A - response.deleteCookie(cookie);
Answer : B
Explaination
You can use setMaxAge to delete a cookie by setting is zero.
Q 10 - Which of the following code is used to delete an attribute from a HTTP Session object in servlets?
A - session.removeAttribute(name)
B - session.alterAttribute(name)
Answer : A
Explaination
session.removeAttribute() removes the object bound with the specified name from this session.
