- 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 - Which of the following is true about servlets?
A - Servlets execute within the address space of a Web server.
B - Servlets are platform-independent because they are written in Java.
C - The full functionality of the Java class libraries is available to a servlet.
Answer : D
Explaination
All of the above stand true for servlets.
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 locale in servlet?
Answer : A
Explaination
request.getlocale() returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
Q 4 - Which of the following code retrieves the value of a request parameter?
B - response.getParameter(name)
Answer : C
Explaination
request.getParameter(name) returns the value of a request parameter as a String, or null if the parameter does not exist.
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 clear any data that exists in the buffer as well as the status code and headers?
Answer : B
Explaination
response.reset() clears any data that exists in the buffer as well as the status code and headers.
Q 7 - When init() method of filter gets called?
B - The init() method is called whenever the servlet being filtered is invoked.
Answer : A
Explaination
The init method is designed to be called only once. It is called by the web container to indicate to a filter that it is being placed into service.
Q 8 - Which of the following is true about javax.servlet.error.request_uri?
Answer : D
Explaination
javax.servlet.error.request_uri attribute gives information about URL calling the servlet and it 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 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 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.
To Continue Learning Please Login
Login with Google