- 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 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 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 parameters in servlet?
A - request.getParameterNames()
B - response.getParameterNames()
Answer : A
Explaination
request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in 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 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 force any content in the buffer to be written to the client?
Answer : C
Explaination
response.flushBuffer() forces any content in the buffer to be written to the client.
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 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.
Answer : B
Explaination
HTTP is a stateless protocol which means each time a client retrieves a Web page, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.
Q 10 - Which of the following code is used to get three-letter abbreviation for this locale's country in servlets?
Answer : A
Explaination
request.getISO3Country() returns a three-letter abbreviation for this locale's country.
To Continue Learning Please Login
Login with Google