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.

Questions and Answers

Servlets Mock Test IV

Answer : A

Explaination

Create cookie using new operator on Cookie class.

Answer : A

Explaination

response.addCookie(cookie) adds cookies in the HTTP response header.

Answer : B

Explaination

You can use setMaxAge to delete a cookie by setting is zero.

Q 8 - Does server automatically keep any record of previous client request?

A - true

B - false

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?

A - Using cookies.

B - Using hidden form fields.

C - Using URL rewriting.

D - All of the above.

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?

A - request.getSession()

B - response.getSession();

C - new Session()

D - None of the above.

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?

A - session.invalidate()

B - response.deleteSession()

C - request.deleteSession()

D - None of the above.

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)

C - session.createAttribute(name,value)

D - None of the above.

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)

C - session.updateAttribute(name,value)

D - None of the above.

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)

C - session.updateAttribute(name)

D - None of the above.

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?

A - session.getSessionId()

B - session.getId()

C - session.getActiveId()

D - None of the above.

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)

C - session.updateAttribute(name)

D - None of the above.

Answer : A

Explaination

session.removeAttribute() removes the object bound with the specified name from this session.

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)

C - request.setIntHeader("Refresh", 5)

D - None of the above.

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?

A - request.getLocale()

B - Locale.getLocale()

C - response.getLocale()

D - None of the above.

Answer : A

Explaination

request.getLocale() returns Local object.

Q 20 - Which of the following code is used to get country/region code in servlets?

A - request.getCountry()

B - Locale.getCountry()

C - response.getCountry()

D - None of the above.

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()

C - response.getDisplayCountry()

D - None of the above.

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?

A - response.getLanguage()

B - Locale.getLanguage()

C - request.getLanguage()

D - None of the above.

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()

C - request.getDisplayLanguage()

D - None of the above.

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?

A - request.getISO3Country()

B - Locale.getISO3Country()

C - response.getISO3Country()

D - None of the above.

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?

A - response.getISO3Language()

B - Locale.getISO3Language()

C - request.getISO3Language()

D - None of the above.

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
servlets-questions-answers.htm
Advertisements