0% found this document useful (0 votes)
7K views11 pages

Servlets Mock Test I

Uploaded by

Mark225user
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7K views11 pages

Servlets Mock Test I

Uploaded by

Mark225user
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SERVLETS MOCK TEST

http://www.tutorialspoint.com Copyright © tutorialspoint.com

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 I

Q 1 - What are Servlets?

A - Java Servlets are programs that run on a Web or Application server.

B - Java Servlets act as a middle layer between a request coming from a Web browser or other
HTTP client and databases or applications on the HTTP server.

C - Both of the above.

D - None of the above.

Q 2 - 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.

D - All of the above.

Q 3 - Which of the following package contains servlet classes?

A - javax.servlet

B - javax.servlet.http

C - Both of the above.

D - None of the above.

Q 4 - Which of the following is the correct order of servlet life cycle phase methods?

A - init, service, destroy


B - initialize, service, destroy

C - init, execute, destroy

D - init, service, delete

Q 5 - When init method of servlet gets called?

A - The init method is called when the servlet is first created.

B - The init method is called whenever the servlet is invoked.

C - Both of the above.

D - None of the above.

Q 6 - Which of the following is true about init method of servlet?

A - The init method simply creates or loads some data that will be used throughout the life of the
servlet.

B - The init method is not called again and again for each user request.

C - Both of the above.

D - None of the above.

Q 7 - When service method of servlet gets called?

A - The service method is called when the servlet is first created.

B - The service method is called whenever the servlet is invoked.

C - Both of the above.

D - None of the above.

Q 8 - Which of the following is true about service method of servlet?

A - The servlet container i. e. webserver calls the service method to handle requests coming from
the client.

B - Each time the server receives a request for a servlet, the server spawns a new thread and
calls service.

C - The service method checks the HTTP request type GET, POST, PUT, DELETE, etc. and calls
doGet, doPost, doPut, doDelete, etc. methods as appropriate.

D - All of the above.

Q 9 - When doGet method of servlet gets called?

A - A GET request results from a normal request for a URL.

B - The service method checks the HTTP request type as GET and calls doGet method.

C - Both of the above.

D - None of the above.


Q 10 - When doPost method of servlet gets called?

A - A POST request results from an HTML form that specifically lists POST as the METHOD.

B - The service method checks the HTTP request type as POST and calls doPost method.

C - Both of the above.

D - None of the above.

Q 11 - When destroy method of servlet gets called?

A - The destroy method is called only once at the end of the life cycle of a servlet.

B - The destroy method is called after the servlet has executed service method.

C - Both of the above.

D - None of the above.

Q 12 - Which of the following is true about destroy method of servlet?

A - After the destroy method is called, the servlet object is marked for garbage collection.

B - The servlet is terminated by calling the destroy method.

C - Both of the above.

D - None of the above.

Q 13 - What is javax.servlet.Servlet?

A - interface

B - abstract class

C - concreate class

D - None of the above.

Q 14 - What is javax.servlet.http.HttpServlet?

A - interface

B - abstract class

C - concreate class

D - None of the above.

Q 15 - 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.
C - Both of the above.

D - None of the above.

Q 16 - Which of the following is true about HTTP Post method?

A - The POST method sends the encoded user information as a seperate message to page
request.

B - The POST method is used to submit form data normally.

C - Both of the above.

D - None of the above.

Q 17 - Which of the following method can be used to get the value of form parameter?

A - request.getParameter

B - request.getParameterValues

C - request.getParameterNames

D - None of the above.

Q 18 - Which of the following method can be used to get the multiple values of a
parameter like checkbox data?

A - request.getParameter

B - request.getParameterValues

C - request.getParameterNames

D - None of the above.

Q 19 - Which of the following method can be used to get complete list of all
parameters in the current request?

A - request.getParameter

B - request.getParameterValues

C - request.getParameterNames

D - None of the above.

Q 20 - Which of the following code is used to set content type of a page to be serviced
using servlet?

A - response.setContentType

B - request.setContentType

C - writer.setContentType

D - None of the above.


Q 21 - Which of the following code is used to get PrintWriter object in servlet?

A - response.getWriter

B - request.getWriter

C - new PrintWriter

D - None of the above.

Q 22 - Which of the following code is used to get cookies in servlet?

A - response.getCookies

B - request.getCookies

C - Cookies.getCookies

D - None of the above.

Q 23 - Which of the following code is used to get names of the attributes in servlet?

A - response.getAttributeNames

B - request.getAttributeNames

C - Header.getAttributeNames

D - None of the above.

Q 24 - 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.

Q 25 - Which of the following code is used to get names of the parameters in servlet?

A - request.getParameterNames

B - response.getParameterNames

C - Header.getParameterNames

D - None of the above.

Q 26 - Which of the following code is used to get session in servlet?

A - request.getSession

B - response.getSession

C - new Session
D - None of the above.

Q 27 - Which of the following code is used to get locale in servlet?

A - request.getlocale

B - response.getLocale

C - new Locale

D - None of the above.

Q 28 - Which of the following code is used to get a particular attribute in servlet?

A - request.getAttributename

B - response.getAttributename

C - new Attributename

D - None of the above.

Q 29 - Which of the following code retrieves the name of the authentication scheme?

A - new AuthType

B - response.getAuthType

C - request.getAuthType

D - None of the above.

Q 30 - Which of the following code retrieves the body of the request as binary data?

A - new InputStream

B - response.getInputStream

C - request.getInputStream

D - None of the above.

Q 31 - Which of the following code retrieves the character encoding used in the body
of this request?

A - new CharacterEncoding

B - response.getCharacterEncoding

C - request.getCharacterEncoding

D - None of the above.

Q 32 - Which of the following code retrieves the MIME type of the body of the request?

A - new MimeType
B - request.getContentType

C - response.getContentType

D - None of the above.

Q 33 - Which of the following code retrieves the context of the request?

A - new ClassContextPath

B - request.getContextPath

C - response.getContextPath

D - None of the above.

Q 34 - Which of the following code retrieves the request header?

A - Header.getHeaderNameheaderName

B - response.getHeaderheaderName

C - request.getHeaderheaderName

D - None of the above.

Q 35 - Which of the following code retrieves the name of the HTTP Method?

A - Header.getMethod

B - response.getMethod

C - request.getMethod

D - None of the above.

Q 36 - Which of the following code retrieves the value of a request parameter?

A - Header.getParametername

B - response.getParametername

C - request.getParametername

D - None of the above.

Q 37 - Which of the following code retrieves any extra path information associated
with the URL the client sent?

A - Header.getPathInfo

B - response.getPathInfo

C - request.getPathInfo

D - None of the above.


Q 38 - Which of the following code retrieves name and version of the protocol?

A - Header.getProtocol

B - response.getProtocol

C - request.getProtocol

D - None of the above.

Q 39 - Which of the following code retrieves the query string that is contained in the
request URL after the path?

A - Header.getQueryString

B - response.getQueryString

C - request.getQueryString

D - None of the above.

Q 40 - Which of the following code retrieves the Internet Protocol IP address of the
client that sent the request?

A - request.getRemoteAddr

B - response.getRemoteAddr

C - Header.getRemoteAddr

D - None of the above.

Q 41 - Which of the following code retrieves the fully qualified name of the client
making this request?

A - request.getRemoteHost

B - response.getRemoteHost

C - Header.getRemoteHost

D - None of the above.

Q 42 - Which of the following code retrieves the login of the user making this request?

A - request.getRemoteUser

B - response.getRemoteUser

C - Header.getRemoteUser

D - None of the above.

Q 43 - Which of the following code retrieves the part of this request's URL from the
protocol name?

A - request.getRequestURI

B - response.getRequestURI
C - Header.getRequestURI

D - None of the above.

Q 44 - Which of the following code retrieves session ID specified by the client?

A - request.getRequestedSessionId

B - response.getRequestedSessionId

C - Header.getRequestedSessionId

D - None of the above.

Q 45 - Which of the following code checks whether this request was made using a
secure channel, such as HTTPS?

A - response.isSecure

B - request.isSafe

C - Header.isSecure

D - None of the above.

Q 46 - Which of the following code returns the port number on which this request was
received?

A - response.getServerPort

B - request.getServerPort

C - Header.getServerPort

D - None of the above.

Q 47 - Which of the following code encodes the specified URL for use in the
sendRedirect method?

A - response.encodeRedirectURLurl

B - request.encodeRedirectURLurl

C - Header.encodeRedirectURLurl

D - None of the above.

Q 48 - Which of the following code encodes the specified URL by including the session
ID in it?

A - response.encodeURLurl

B - request.encodeURLurl

C - Header.encodeURLurl

D - None of the above.


Q 49 - Which of the following code indicates whether the named response header has
already been set?

A - response.containsHeaderheaderName

B - request.containsHeaderheaderName

C - Header.containsHeaderheaderName

D - None of the above.

Q 50 - Which of the following code indicates whether the response has been
committed?

A - response.isCommitted

B - request.isCommitted

C - Header.isCommitted

D - None of the above.

ANSWER SHEET

Question Number Answer Key

1 C

2 D

3 C

4 A

5 A

6 C

7 B

8 D

9 C

10 C

11 A

12 C

13 A

14 B

15 C

16 C

17 A

18 B
19 C

20 A

21 A

22 B

23 B

24 B

25 A

26 A

27 A

28 A

29 C

30 C

31 C

32 B

33 B

34 C

35 C

36 C

37 C

38 C

39 C

40 A

41 A

42 A

43 A

44 A

45 B

46 B

47 A

48 A

49 A

50 A

Processing math: 100%

You might also like