- 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 service() method of servlet gets called?
A - The service() method is called when the servlet is first created.
B - The service() method is called whenever the servlet is invoked.
Answer : B
Explaination
Each time the server receives a request for a servlet, the server spawns a new thread and calls service() method.
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 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 the MIME type of the body of the request?
Answer : B
Explaination
request.getContentType() returns the MIME type of the body of the request, or null if the type is not known.
Q 5 - Which of the following code retrieves the part of this request's URL from the protocol name?
Answer : A
Explaination
request.getRequestURI() returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
Q 6 - Which of the following code can be used to add a header?
A - request.addHeader(name,value)
B - response.addDateHeader(name,value)
Answer : B
Explaination
response.addHeader(name,date) adds a response header with the given name and value.
Q 7 - Which of the following code can be used to set the preferred buffer size for the body of the response?
A - response.setBufferSize(size)
B - request.setBufferSize(size)
Answer : A
Explaination
response.setBufferSize(size) sets the preferred buffer size 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 is used to add an attribute in a HTTP Session object in servlets?
A - session.addAttribute(name,value)
B - session.setAttribute(name,value)
Answer : B
Explaination
session.setAttribute() binds an object to this session, using the name specified.
Q 10 - Which of the following code is used to get language code in servlets?
Answer : C
Explaination
request.getLanguage() returns the language code in lower case for this locale in ISO 639 format.