- 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 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 code is used to set content type of a page to be serviced using servlet?
Answer : A
Explaination
You call response.setContentType() method to set content type of a page to be serviced using servlet.
Q 3 - Which of the following code retrieves the name of the authentication scheme?
Answer : C
Explaination
request.getAuthType() returns the name of the authentication scheme used to protect the servlet, for example, BASIC or SSL or null if the JSP was not protected.
Q 4 - Which of the following code retrieves the query string that is contained in the request URL after the path?
Answer : C
Explaination
request.getQueryString() returns the query string that is contained in the request URL after the path.
Q 5 - Which of the following code indicates whether the named response header has already been set?
A - response.containsHeader(headerName)
B - request.containsHeader(headerName)
Answer : A
Explaination
response.containsHeader(headerName) returns a boolean indicating whether the named response header has already been set.
Q 6 - Which of the following code can be used to redirect user to different url?
A - request.sendRedirect(location)
B - response.sendRedirect(location)
Answer : B
Explaination
response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.
Q 7 - Which of the following code can be used to set the length of content of body of the response?
A - request.setContentLength(length)
B - response.setContentLength(length)
Answer : B
Explaination
response.setContentLength(length) sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
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 delete a cookie in servlet?
A - response.deleteCookie(cookie);
Answer : B
Explaination
You can use setMaxAge to delete a cookie by setting is zero.
Q 10 - Which of the following code is used to get country/region code in servlets?
Answer : A
Explaination
request.getCountry() returns the country/region code in upper case for this locale in ISO 3166 2-letter format.
