- 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 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 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 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 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.request_uri?
Answer : D
Explaination
javax.servlet.error.request_uri attribute gives information about URL calling the servlet and it can be stored and analysed after storing in a java.lang.String 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 name in servlets?
A - response.getDisplayLanguage()
B - Locale.getDisplayLanguage()
Answer : C
Explaination
request.getDisplayLanguage() returns a name for the locale's language that is appropriate for display to the user.
