Which method in the HttpServlet class services the HTTP POST request?
(Select one)
a doPost(ServletRequest, ServletResponse)
b doPOST(ServletRequest, ServletResponse)
c servicePost(HttpServletRequest, HttpServletResponse)
d doPost(HttpServletRequest, HttpServletResponse)
Answer:
d
Which element is used to specify useful information about an initialization
parameter of a servlet in the deployment descriptor? (Select one)
a param-description
b description
c info
d param-info
e init-param-info
Answer:
b
Which of the following methods will be invoked when a ServletContext is
destroyed? (Select one)
a contextDestroyed() of javax.servlet.ServletContextListener
b contextDestroyed() of javax.servlet.HttpServletContextListener
c contextDestroyed() of javax.servlet.http.ServletContextListener
d contextDestroyed() of javax.servlet.http.HttpServletContextListener
Answer:
a
Explanation
Remember that the concept of servlet context applies to all the servlets and not
just HttpServlets. Therefore, interfaces related to servlet context belong to the
javax.servlet package.
Which elements are allowed in the element of the deployment
descriptor? (Select three)
a
b
c
d
e
Answers:
a, c, and d
Explanation
Answer a is correct because you can map filters to named servlets, as well as URL
patterns.
When servlet init parameter will be read ?
A When client makes a request.
B When starting server
C When container initializes the servlet
D When container shuts down.
Answer:
C
When the container initializes the servlet, it reads the DD and creates a parameter list for ServletConfig. These parameters are read only once at the time of initialization only
Which of the following interfaces or classes is used to retrieve the session associated
with a user? (Select one)
a GenericServlet
b ServletConfig
c ServletContext
d HttpServlet
e HttpServletRequest
f HttpServletResponse
Answer:
e
Explanation
The session associated with a user can only be retrieved using the HttpServlet-
Request.getSession() method.
Which of the following correctly defines data integrity? (Select one)
a It guarantees that information is accessible only to certain users.
b It guarantees that the information is kept in encrypted form on the server.
c It guarantees that unintended parties cannot read the information during transmission
between the client and the server.
d It guarantees that the information is not altered during transmission between the client
and the server.
Answer:
d
Explanation
Answers a and c describe authorization and confidentiality. Encrypting data kept
on the server may be part of some security plans, but is not covered by the servlet
specification.
Which method is used to read the context initialization parameter ? Select two
A getServletConfig().getInitParameter();
B getServletContext().getInitParameter();
C getServletConfig().getContextParameter();
D getServletContext().getServletParameter();
E getServletConfig().getServletContext().getInitParameter();
Answer:
B and E
Option A is incorrect because it reads servlet initialization parameter only, not context initialization parameter. Option c and d are incorrect because , they are invalid methods. Option E is correct because always a ServletConfig contains a reference to the ServletContext.
What getInitParameterNames() of ServletContext does ?
A Returns the init parameters for a servlet
B Returns the init parameter names of a servlet
C Returns the init parameter names of the context
D All of the above.
Answer:
C
getInitParameterNames() returns the names of the context's initialization parameters as an Enumeration
Which is the correct way to set a context initialization parameter ?
A getServletContext().setInitParameter();
B getServletConfig().setInitParameter();
C using DD
D None of the above.
Answer:
C
The only way to set a context initialization parameter is by using tag in the DD only. We cannot set the context param programmatically
Consider the following code and select the correct statement about it from the
options below. (Select one)
<html><body>
<%! int aNum=5 %>
The value of aNum is <%= aNum %>
</body></html>
a It will print "The value of aNum is 5" to the output.
b It will flag a compile-time error because of an incorrect declaration.
c It will throw a runtime exception while executing the expression.
d It will not flag any compile time or runtime errors and will not print anything to the
output.
Answer:
b
What will be the output of the following code? (Select one)
<html><body>
<% x=3; %>
<% int x=5; %>
<%! int x=7; %>
x = <%=x%>, <%=this.x%>
</body></html>
a x = 3, 5
b x = 3, 7
c x = 5, 3
d x = 5, 7
e Compilation error
Answer:
c