- 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 - 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 session in servlet?
Answer : A
Explaination
request.getSession() returns the current session associated with this request, or if the request does not have a session, creates one.
Q 4 - Which of the following code retrieves the request header?
A - Header.getHeaderName(headerName)
B - response.getHeader(headerName)()
Answer : C
Explaination
request.getHeader(headerName) returns the value of the specified request header as a String.
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 send an error response to the client using the specified status code and error message?
A - request.sendError(statusCode,message)
B - response.sendError(statusCode,message)
Answer : B
Explaination
response.sendError(statusCode,message) sends an error response to the client using the specified status code and error message.
Q 7 - Which of the following is true about filters?
Answer : C
Explaination
Servlet Filters are Java classes that can be used to intercept requests from a client before they access a resource at back end and to manipulate responses from server before they are sent back to the client.
Q 8 - Which of the following is true about init() method of filter?
B - The init() method is not called again and again for each user request.
Answer : C
Explaination
The init method is designed to be called only once. It is called when the filter is first created, and not called again for each user request. It simply creates or loads some data that will be used throughout the life of the filter.
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 set auto refresh of a page after 5 seconds?
A - session.setIntHeader("Refresh", 5)
B - response.setIntHeader("Refresh", 5)
Answer : B
Explaination
response.setIntHeader("Refresh", 5) sets refresh, autoload time as 5 seconds.
To Continue Learning Please Login
Login with Google