![Servlets Tutorial](/servlets/images/servlets-mini-logo.jpg)
- 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.
![Questions and Answers](/images/questions_and_answers.png)
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 - Which of the following is true about HTTP Post method?
A - The POST method sends the encoded user information as a seperate message to page request.
Answer : C
Explaination
The POST method sends the encoded user information as a seperate message to page request. It is used to submit form data normally.
Q 3 - Which of the following code is used to get names of the attributes in servlet?
A - response.getAttributeNames()
B - request.getAttributeNames()
Answer : B
Explaination
request.getAttributeNames() returns an enumeration containing the names of the attributes available to 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 checks whether this request was made using a secure channel, such as HTTPS?
Answer : B
Explaination
request.isSecure() returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
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 - 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.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 get language name in servlets?
A - response.getDisplayLanguage()
B - Locale.getDisplayLanguage()
Answer : C
Explaination
request.getDisplayLanguage() returns a name for the locale's language that is appropriate for display to the user.
To Continue Learning Please Login