- 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 service() method of servlet?
Answer : D
Explaination
The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client. Each time the server receives a request for a servlet, the server spawns a new thread and calls service. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.
Q 2 - Which of the following method can be used to get the value of form parameter?
B - request.getParameterValues()
Answer : A
Explaination
You call request.getParameter() method to get the value of a form parameter.
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 name of the HTTP Method?
Answer : C
Explaination
request.getMethod() returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
Q 5 - Which of the following code returns the port number on which this request was received?
Answer : B
Explaination
request.getServerPort() returns the port number on which this request was received.
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 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 request attributes that an error-handling servlet can access to analyse the nature of error/exception?
A - javax.servlet.error.status_code
B - javax.servlet.error.exception_type
Answer : D
Explaination
All of the above request attributes can be accessed by error-handling servlet.
Q 9 - Which of the following code is used to delete a HTTP Session object in servlets?
Answer : A
Explaination
session.invalidate() invalidates this session and unbinds any objects bound to it.
Q 10 - Which of the following code is used to get country/region name in servlets?
A - request.getDisplayCountry()
B - Locale.getDisplayCountry()
Answer : A
Explaination
request.getDisplayCountry() returns the country/region name for the locale's country that is appropriate for display to the user.
