- 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 - Mock Test
This section presents you various set of Mock Tests related to Servlets Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
Servlets Mock Test IV
Q 1 - Which of the following is true about javax.servlet.error.status_code?
Answer : C
Explaination
javax.servlet.error.status_code attribute gives status code which can be stored and analysed after storing in a java.lang.Integer data type.
Q 2 - Which of the following is true about javax.servlet.error.exception_type?
Answer : B
Explaination
javax.servlet.error.exception_type attribute gives information about exception type which can be stored and analysed after storing in a java.lang.Class data type.
Q 3 - Which of the following is true about javax.servlet.error.message?
Answer : A
Explaination
javax.servlet.error.message attribute gives information exact error message which can be stored and analysed after storing in a java.lang.String data type.
Q 4 - 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 5 - How to create a cookie in servlet?
B - Use request.getCookie() method
Answer : A
Explaination
Create cookie using new operator on Cookie class.
Q 6 - Which of the following code sends a cookie in servlet?
A - response.addCookie(cookie);
B - response.sendCookie(cookie);
Answer : A
Explaination
response.addCookie(cookie) adds cookies in the HTTP response header.
Q 7 - 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.
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 9 - Which of the following way can be used to keep track of previous client request?
Answer : D
Explaination
All of the above can be used to keep track of previous client request.
Q 10 - Which of the following code is used to get a HTTP Session object in servlets?
Answer : A
Explaination
request.getSession() is used to get a HTTP Session object in servlets.
Q 11 - 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 12 - 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 13 - Which of the following code is used to update an attribute in a HTTP Session object in servlets?
A - session.setAttribute(name,value)
B - session.alterAttribute(name,value)
Answer : A
Explaination
session.setAttribute() binds an object to this session, using the name specified.
Q 14 - Which of the following code is used to get an attribute in a HTTP Session object in servlets?
A - session.getAttribute(name)
B - session.alterAttribute(name)
Answer : A
Explaination
session.getAttribute() returns the object bound with the specified name in this session, or null if no object is bound under the name.
Q 15 - Which of the following code is used to get session id of a HTTP Session object in servlets?
Answer : B
Explaination
session.getId() returns a string containing the unique identifier assigned to this session.
Q 16 - Which of the following code is used to delete an attribute from a HTTP Session object in servlets?
A - session.removeAttribute(name)
B - session.alterAttribute(name)
Answer : A
Explaination
session.removeAttribute() removes the object bound with the specified name from this session.
Q 17 - Which of the following code is used to set the session timeout in servlets?
A - session.setMaxInactiveInterval(interval)
B - response.setMaxInactiveInterval(interval)
Answer : A
Explaination
You can call public void setMaxInactiveInterval(int interval) method of session to set the timeout for a session individually.
Q 18 - 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.
Q 19 - Which of the following code is used to get locale in servlets?
Answer : A
Explaination
request.getLocale() returns Local object.
Q 20 - 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.
Q 21 - 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.
Q 22 - Which of the following code is used to get language code in servlets?
Answer : C
Explaination
request.getLanguage() returns the language code in lower case for this locale in ISO 639 format.
Q 23 - 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.
Q 24 - 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.
Q 25 - Which of the following code is used to get three-letter abbreviation for this locale's language in servlets?
Answer : C
Explaination
request.getISO3Language() returns a three-letter abbreviation for this locale's language.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | C |
2 | B |
3 | A |
4 | D |
5 | A |
6 | A |
7 | B |
8 | B |
9 | D |
10 | A |
11 | A |
12 | B |
13 | A |
14 | A |
15 | B |
16 | A |
17 | A |
18 | B |
19 | A |
20 | A |
21 | A |
22 | C |
23 | C |
24 | A |
25 | C |