Unit-3 Servlets MCQ'S: Answer: A
Unit-3 Servlets MCQ'S: Answer: A
Unit-3 Servlets MCQ'S: Answer: A
Q 3 - Which of the following code is used to get names of the headers in
servlet?
A - response.getHeaderNames()
B - request.getHeaderNames()
C - Header.getHeaderNames()
D - None of the above.
Answer : B
Q 7 - Which of the following code can be used to set the locale of the
response?
A - request.setLocale(locale)
B - response.setLocale(locale)
C - header.setLocale(locale)
D - None of the above.
Answer : B
14. Which of the following code is used to get an attribute in a HTTP Session
object in servlets?
a) session.getAttribute(String name)
b) session.alterAttribute(String name)
c) session.updateAttribute(String name)
d) session.setAttribute(String name)
Answer: a
15. Which of the following code retrieves the body of the request as binary
data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = response.getInputStream()
c) DataInputStream data = request.getInputStream()
d) DataInputStream data = request.fetchInputStream()
Answer: c
21. Which class provides stream to read binary data such as image etc. from the
request object?
a. ServltInputStream
b. ServletOutputStream
c. Both A & B
d. None of the above
ANSWER: A
23.Which methods are used to bind the objects on HttpSession instance and get
the objects?
a. setAttribute
b. getAttribute
c. Both A & B
d. None of the above
ANSWER: C
24. Which type of ServletEngine is a server that includes built-in support for servlets?
a. Add-on ServletEngine
b. Embedded ServletEngine
c. Standalone ServletEngine
d. None of the above
ANSWER:c
25. What type of servlets use these methods doGet(), doPost(),doHead, doDelete(),
doTrace()?
a. Genereic Servlets
b. HttpServlets
c. All of the above
d. None of the above
ANSWER:b
26. Which cookie it is valid for single session only and it is removed each time when the
user closes the browser?
a. Persistent cookie
b. Non-persistent cookie
c. All the above
d. None of the above
ANSWER:b
27. Which method is used to send the same request and response objects to another
servlet in RequestDispacher ?
a. forward()
b. sendRedirect()
c. Both A & B
d. None of the above
ANSWER:a
28. Which packages represent interfaces and classes for servlet API?
a. javax.servlet
b. javax.servlet.http
c. Both A & B
d. None of the above
ANSWER:c
29. Which class can handle any type of request so that it is protocol-independent?
a. GenericServlet
b. HttpServlet
c. Both A & B
d. None of the above
ANSWER:A
30. Which object is created by the web container at time of deploying the project?
a. ServletConfig
b. ServletContext
c. Both A & B
d. None of the above
ANSWER:b
34. Which JDBC driver Type(s) can be used in either applet or servlet code?
a) Both Type 1 and Type 2
b) Both Type 1 and Type 3
c) Both Type 3 and Type 4
d) Type 4 only
Answer: c
Explanation: In a Type 3 driver, a three-tier approach is used to accessing databases. The
JDBC clients use standard network sockets to communicate with an middleware application
server. In a Type 4 driver, a pure Java-based driver that communicates directly with vendor’s
database through socket connection.
35. Which are the session tracking techniques?
i. URL rewriting ii. Using session object
iii.Using response object iv. Using hidden fields
v. Using cookies vi. Using servlet object
a) i, ii, iii, vi
b) i, ii, iii, v
c) i, vi, iii, v
d) ) i, ii, iv, v
Answer: d
36. Which class can handle any type of request means protocol-independent?
(A) HttpServlets
(B) GenereicServlets
(C) Both A & B
(D) None of Above
Answer: b
37. Which object is created by the web container at time of deploying the project?
(A) ServletContext
(B) ServletConfig
(C) Both A & B
(D) None of Above
Answer: a
38. Which of following method is used to send the same request and response objects to
another servlet using RequestDispatcher ?
(A) forward()
(B) sendRedirect()
(C) Both A & B
(D) None of Above
Answer: a
39. A deployment descriptor describes ___________.
(A) Web component request setting
(B) Web component response setting
(C) Web component request and response objects
(D) Web component setting
Answer: d
40. Which cookie is valid for single session only and it is removed when the user closes the
browser?
(A) Non-persistent cookie
(B) Persistent cookie
(C) Both A & B
(D) None of Above
Answer: A
41. Which of following session tracking method leads to high network traffic?
(A) URL rewriting
(B) SSL sessions
(C) Cookies
(D) None of Above
Answer: A
42. What is difference between servlet and applet?
1) Servlet create static web pages where as applet creates dynamic web pages
2) Servlet executes on server where as applet executes on browser
3) Servlet have no GUI where as applet has GUI
4) Servlet can handle only a single request where as applet can handle multiple requests
(A) 1 & 2 are correct
(B) 1, 2 & 3 are correct
(C) 2 & 3 are correct
(D) 2, 3 & 4 are correct
Answer: C
43. Which method creates unique fields in the HTML which are not shown to the user?
(A) URL writing
(B) HTML Blank Field
(C) HTML invisible field
(D) HTML Hidden field
Answer:D
44. Which of following is correct syntax to delete an attribute from HttpSession object in
servlet?
(A) session.deleteAttribute(name)
(B) session.removeAttribute(name)
(C) session.alterAttribute(name)
(D) None of Above
Answer:B