Servlets Mock Test I
Servlets Mock Test I
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.
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.
A - javax.servlet
B - javax.servlet.http
Q 4 - Which of the following is the correct order of servlet life cycle phase methods?
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.
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.
B - The service method checks the HTTP request type as GET and calls doGet method.
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.
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.
A - After the destroy method is called, the servlet object is marked for garbage collection.
Q 13 - What is javax.servlet.Servlet?
A - interface
B - abstract class
C - concreate class
Q 14 - What is javax.servlet.http.HttpServlet?
A - interface
B - abstract class
C - concreate class
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.
A - The POST method sends the encoded user information as a seperate message to page
request.
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
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
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
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
A - response.getWriter
B - request.getWriter
C - new PrintWriter
A - response.getCookies
B - request.getCookies
C - Cookies.getCookies
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
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
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
A - request.getSession
B - response.getSession
C - new Session
D - None of the above.
A - request.getlocale
B - response.getLocale
C - new Locale
A - request.getAttributename
B - response.getAttributename
C - new Attributename
Q 29 - Which of the following code retrieves the name of the authentication scheme?
A - new AuthType
B - response.getAuthType
C - request.getAuthType
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
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
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
A - new ClassContextPath
B - request.getContextPath
C - response.getContextPath
A - Header.getHeaderNameheaderName
B - response.getHeaderheaderName
C - request.getHeaderheaderName
Q 35 - Which of the following code retrieves the name of the HTTP Method?
A - Header.getMethod
B - response.getMethod
C - request.getMethod
A - Header.getParametername
B - response.getParametername
C - request.getParametername
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
A - Header.getProtocol
B - response.getProtocol
C - request.getProtocol
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
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
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
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
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
A - request.getRequestedSessionId
B - response.getRequestedSessionId
C - Header.getRequestedSessionId
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
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
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
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
A - response.containsHeaderheaderName
B - request.containsHeaderheaderName
C - Header.containsHeaderheaderName
Q 50 - Which of the following code indicates whether the response has been
committed?
A - response.isCommitted
B - request.isCommitted
C - Header.isCommitted
ANSWER SHEET
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