Question No :1
Name the class that includes the getSession method that is used to get the HttpSession object
(Choose correct one from multiple below)
1. HttpServletRequest
2. HttpServletResponse
3. SessionContext
4. SessionConfig
correct is :1
Explanations :The class HttpServletRequest defines the getSession method
------------------------------------------------------------------------------
Question No :2
To send text outptut in a response, the following method of HttpServletResponse
may be used to get the appropriate Writer/Stream object.
Select the one correct answer.
(Choose correct one from multiple below)
1. getStream
2. getOutputStream
3. getBinaryStream
4. getWriter
correct is :4
Explanations :The getOutputStream method is used to get an output stream to send binary data.
The getWriter method is used to get a PrintWriter object that can be used to send text data.
------------------------------------------------------------------------------
Question No :3
To send binary outptut in a response, the following method of HttpServletResponse may be used
to get the appropriate Writer/Stream object.
Select the one correct answer
(Choose correct one from multiple below)
1. getStream
2. getOutputStream
3. getBinaryStream
4. getWriter
correct is :2
Explanations :The getOutputStream method is used to get an output stream to send binary data.
The getWriter method is used to get a PrintWriter object that can be used to send text data.
------------------------------------------------------------------------------
Question No :4
Which of the following statements are correct about the status of the Http response.
Select the one correct answer
(Choose correct one from multiple below)
1. A status of 200 to 299 signifies that the request was succesful.
2. A status of 300 to 399 are informational messages
3. A status of 400 to 499 indicates an error in the server
4. A status of 500 to 599 indicates an error in the client
correct is :1
Explanations :The following table specifies the specific the status code of Http response.
Status Code Purpose
100-199 Informational
200-299 Request was succesful
300-399 Request file has moved.
400-499 Client error
500-599 Server error.
------------------------------------------------------------------------------
Question No :5
The sendRedirect method defined in the HttpServlet class is equivalent to invoking
the setStatus method with the following parameter and a Location header in the URL.
Select the one correct answer
(Choose correct one from multiple below)
1. SC_OK .
2. SC_MOVED_TEMPORARILY
3. SC_NOT_FOUND
4. SC_INTERNAL_SERVER_ERROR
correct is :2
Explanations :sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY
(302) response code and a location header in the URL
------------------------------------------------------------------------------
Question No :6
The sendError method defined in the HttpServlet class is equivalent to invoking the setStatus
method with the following parameter.
Select the one correct answer
(Choose correct one from multiple below)
1. SC_OK .
2. SC_MOVED_TEMPORARILY
3. SC_NOT_FOUND
4. SC_INTERNAL_SERVER_ERROR
correct is :3
Explanations :sendError(String URL) is equivalent to sending SC_NOT_FOUND (404) response
code
------------------------------------------------------------------------------
Question No :7
Which of the following statements is correct. Select the one correct answer
(Choose correct one from multiple below)
1. The response from the server to a HEAD request consists of status line, content type and the
document.
2. The response from the server to a GET request does not contain a document
3. The setStatus method defined in the HttpServletRequest class takes an int as an argument and
sets the status of Http response
4. The HttpServletResponse defines constants like SC_NOT_FOUND that may be used as a
parameter to setStatus method.
correct is :4
Explanations :The response from the server to a HEAD request does not contain the document,
whereas the response to GET request does contain a document.
So A and B are incorrect.
C is incorrect because setStauts is defined in HttpServletResponse
------------------------------------------------------------------------------
Question No :8
When the servlet container determines that a servlet should be removed from service . _____
method should be called.
(Choose correct one from multiple below)
1. destroy()
2. init()
3. service()
4. All of the above
correct is :1
Explanations :When the servlet container determines that a servlet should be removed from
service,
it calls the destroy method of the Servlet interface to allow the servlet to release any resources it is
using and save any persistent state
------------------------------------------------------------------------------
Question No :9
All the request handle by _______ method .
(Choose correct one from multiple below)
1. init()
2. service()
3. destroy()
4. None of the above
correct is :2
Explanations :After a servlet is properly initialized, the servlet container may use it to handle client
requests.
Requests are represented by request objects of type ServletRequest. The servlet fills out
response to requests by calling methods of a provided object of type ServletResponse.
These objects are passed as parameters to the service method of the Servlet interface
------------------------------------------------------------------------------
Question No :10
Which statement is true about Servlet class loading ?
(Choose correct one from multiple below)
1. on startup servlet container loads the web.xml file and load the servlet class based on the load-
on-startup element in web.xml
2. on startup servlet container loads does not read the web.xml file
3. both are true
4. None of the above
correct is :1
Explanations :servlet container loads the web.xml file and load the servlet class based on the load-
on-startup element in web.xml
------------------------------------------------------------------------------
Question No :11
Which statement is correct about Servlet class initialization?
(Choose correct one from multiple below)
1. After the servlet object is instantiated, the container must initialize the servlet before it can
handle requests from clients.
2. Initialization is provided so that a servlet can read configuration data using getInitParameter.
3. The container initializes the servlet instance by calling the init method
4. All of the above
correct is :4
Explanations :After the servlet object is instantiated, the container must initialize the servlet before
it can handle requests from clients.
Initialization is provided so that a servlet can read persistent configuration data, initialize costly
resources (such as JDBC connections), and perform other one-time activities.
The container initializes the servlet instance by calling the init method.
------------------------------------------------------------------------------
Question No :12
What is the correct sequence about servlet life cycle ?
(Choose correct one from multiple below)
1. (1) call the init method, (2) call the service method, and (3) call destroy method
2. (1) call the service method, and (2) call destroy method
3. Can't say
4. None of the above
correct is :1
Explanations :servlet life cycle sequence
(1) servlet class loading,
(2) servlet instantiation,
(3) call the init method,
(4) call the service method, and
(5) call destroy method
------------------------------------------------------------------------------
Question No :13
Is the servlet life cycle sequence (1) servlet class loading, (2) servlet instantiation, (3) call the init
method, (4) call the service method, and (5) call destroy method
true ?
(Choose correct one from multiple below)
1. true
2. false
3. None of the above
4. None of the above
correct is :1
Explanations :servlet life cycle sequence
(1) servlet class loading,
(2) servlet instantiation,
(3) call the init method,
(4) call the service method, and
(5) call destroy method
------------------------------------------------------------------------------
Question No :14
Which statement is true ?
(Choose correct one from multiple below)
1. HttpServletResponse.addCookie(Cookie) method add cookies to the client browser.
2. HttpServletResponse.setCookie(Cookie) method set cookies to the client browser.
3. Both are true
4. None of the above
correct is :1
Explanations :HttpServletResponse.addCookie(Cookie) method add cookies to the client browser.
------------------------------------------------------------------------------
Question No :15
________ provides an output stream for sending BINARY data to the client.
(Choose correct one from multiple below)
1. ServletResponse.getOutputStream() method retun ServletOutputStream
2. ServletResponse.getInputStream() method retun ServletInputStream
3. No such method is available
4. None of the above
correct is :1
Explanations :ServletResponse.getOutputStream() provides an output stream for sending BINARY
data to the client.
------------------------------------------------------------------------------
Question No :16
Which statement is true about HttpServletResponse.sendRedirect(String location) ?
(Choose correct one from multiple below)
1. this is new server call to URL.
2. only data available in session can be retrived after sendRedirect.
3. data avilable in request object can't be available after sendRedirect.
4. All of the above
correct is :4
Explanations :only data available in session can be retrived after sendRedirect.
------------------------------------------------------------------------------
Question No :17
sendRedirect(java.lang.String location) method belongs to which class ?
(Choose correct one from multiple below)
1. HttpServletResponse
2. HttpServletRequest
3. ServletResponse
4. All of the above
correct is :4
Explanations :public interface HttpServletResponse extends javax.servlet.ServletResponse {
public void sendRedirect(java.lang.String location) throws IOException;
}
------------------------------------------------------------------------------
Question No :18
Which statement is true about PrintWriter ?
(Choose correct one from multiple below)
1. PrintWriter object that can send character text to the client.
2. The PrintWriter uses the character encoding returned by getCharacterEncoding().
3. Calling flush() on the PrintWriter commits the response.
4. All of the above
correct is :4
Explanations :PrintWriter object that can send character text to the client.
The PrintWriter uses the character encoding returned by getCharacterEncoding().
Calling flush() on the PrintWriter commits the response .
------------------------------------------------------------------------------
Question No :19
What are the ways define content type ?
(Choose correct one from multiple below)
1. ServletResponse.setContentType("text/html");
2. HttpServletResponse.setHeader("Content-Type", "text/html");
3. Both are true
4. None of the above
correct is :3
Explanations :There are 2 ways to define content type:
ServletResponse.setContentType(String);
HttpServletResponse.setHeader("Content-Type", "text/html");
------------------------------------------------------------------------------
Question No :20
A servlet can access the headers of an HTTP request through the _____________ methods of the
HttpServletRequest interface.
(Choose correct one from multiple below)
1. getHeader
2. getHeaders
3. getHeaderNames
4. All of the above
correct is :4
Explanations :getHeader:
Returns the value of the specified request header as a String.
getHeaders:
Returns all the values of the specified request header as an Enumeration of String objects.
getHeaderNames:
Returns an enumeration of all the header names this request contains. If the request has no
headers, this method returns an empty enumeration.
------------------------------------------------------------------------------
Question No :21
Which statement is true about HttpServletRequest.getParameterMap() ?
(Choose correct one from multiple below)
1. Returns an immutable java.util.Map,The keys in the parameter map are of type String.
2. Returns an immutable java.util.Map,The values in the parameter map are of type String array..
3. both are true
4. None of the above
correct is :3
Explanations :getParameterMap :
Returns an immutable java.util.Map containing parameter names as keys and parameter values as
map values.
The keys in the parameter map are of type String. The values in the parameter map are of type
String array
------------------------------------------------------------------------------
Question No :22
Which statement is true about HttpServletRequest.getParameterValues() ?
(Choose correct one from multiple below)
1. Returns an array of String objects containing all of the values the given request parameter has,
or null if the parameter does not exist
2. Returns an array of Objects containing all of the values the given request parameter has, or null
if the parameter does not exist
3. both are true
4. None of the above
correct is :1
Explanations :getParameterValues :
Returns an array of String objects containing all of the values the given request parameter has, or
null if the parameter does not exist.
If the parameter has a single value, the array has a length of 1.
------------------------------------------------------------------------------
Question No :23
Which statement is true about HttpServletRequest.getParameterNames() ?
(Choose correct one from multiple below)
1. Returns an Enumeration of String objects containing the names of the parameters contained in
this request
2. If the request has no parameters, the method returns an EMPTY Enumeration
3. both are true
4. None of the above
correct is :3
Explanations :getParameterNames :
Returns an Enumeration of String objects containing the names of the parameters contained in
this request.
If the request has no parameters, the method returns an EMPTY Enumeration.
------------------------------------------------------------------------------
Question No :24
Which statement is true about HttpServletRequest.getParameter(String abc) ?
(Choose correct one from multiple below)
1. Returns the value of a request parameter as a String, or null if the parameter does not exist
2. Returns the value of a request parameter as a Object, or null if the parameter does not exist
3. You should only use this method when you are sure the parameter has only ONE value
4. 1 and 3 is true
correct is :4
Explanations :getParameter :
Returns the value of a request parameter as a String, or null if the parameter does not exist.
Request parameters are extra information sent with the request. For HTTP servlets, parameters
are contained in the query string or posted form data.
------------------------------------------------------------------------------
Question No :25
"HttpServlet extends GenericServlet"
Is the above statement is true ?
(Choose correct one from multiple below)
1. true
2. false
3. can't say
4. None of the above
correct is :1
Explanations :public abstract class HttpServlet extends GenericServlet
implements Serializable
{
}
------------------------------------------------------------------------------
Question No :26
getServletContext() method is from _____________ class.
(Choose correct one from multiple below)
1. HttpServlet
2. GenericServlet
3. Can't say
4. None of the above
correct is :2
Explanations :public abstract class GenericServlet
implements Servlet, ServletConfig, Serializable
{
public ServletContext getServletContext()
{
return getServletConfig().getServletContext();
}
}
------------------------------------------------------------------------------
Question No :27
Which is correct doGet() method in HttpServlet ?
(Choose correct one from multiple below)
1. protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
2. public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
3. None of the above
4. None of the above
correct is :1
Explanations :protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException is correct one.
------------------------------------------------------------------------------
Question No :28
Which is correct doPost() method in HttpServlet ?
(Choose correct one from multiple below)
1. protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
2. public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
3. Both are true
4. None of the above
correct is :1
Explanations :protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException is the correct one.
------------------------------------------------------------------------------
Question No :29
"Hides form data from users because it is not passed as a query string, but in the message body. "
above statement is refer to _______ method ?
(Choose correct one from multiple below)
1. GET
2. POST
3. DELETE
4. None of the above
correct is :2
Explanations :POST method technical characteristics.
Sends information to the server such as form fields, large text bodies, and key-value pairs.
Hides form data from users because it is not passed as a query string, but in the message body.
Sends UNLIMITED length data as part of its HTTP request body.
For sending ASCII (text) or binary data.
Disallows bookmarks.
------------------------------------------------------------------------------
Question No :30
Which statement is true about "POST" method?
(Choose correct one from multiple below)
1. The HTTP POST method allows the client to send data of UNLIMITED length to the Web server
a single time
2. Users can't see data in the browser's address bar
3. sending ASCII (text) or binary data both
4. All of the above
correct is :4
Explanations :POST method technical characteristics.
Sends information to the server such as form fields, large text bodies, and key-value pairs.
Hides form data from users because it is not passed as a query string, but in the message body.
Sends UNLIMITED length data as part of its HTTP request body.
For sending ASCII (text) or binary data.
Disallows bookmarks.
------------------------------------------------------------------------------
Question No :31
Which statement is true about "GET" method?
(Choose correct one from multiple below)
1. Users can see data in the browser's address bar
2. Query length is limited (it depends on servlet container's plaform, but usually should not exceed
1024 bytes).
3. Only ASCII (text) data can be sent to server with GET method
4. All of the above.
correct is :4
Explanations :GET method technical characteristics.
Only ASCII (text) data can be sent to server with GET method.
------------------------------------------------------------------------------
Question No :32
Which statements are true about the method log?
(Choose correct one from multiple below)
1. log is a method GenericServlet class
2. log is a method of ServletContext interface
3. log is an overloaded method
4. All of the above
correct is :4
Explanations :All of the above
------------------------------------------------------------------------------
Question No :33
Given the following web application deployment descriptor:
<web-app>
<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
...
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
which statements are true?
(Choose correct one from multiple below)
1. url-pattern can't be defined that way.
2. servlet-mapping element should be inside servlet element
3. if you make the http call: http://localhost:8080/Hello.jsp the servlet container will execute
TestServlet.
4. It would work with any extension excepting jsp,html,htm
correct is :3
Explanations :if you make the http call: http://localhost:8080/Hello.jsp the servlet container will
execute TestServlet.
------------------------------------------------------------------------------
Question No :34
Which statements are correct about the way a servlet can acces its initialization parameters?
(Choose correct one from multiple below)
1. By simply calling getInitParameter from any of the servlets methods (for example doGet)
2. It must be done by calling getServletConfig().getInitParaemter
3. It can only be done by overriding the method init(ServletConfig config)
4. It can be done by calling getServletContext().getInitParameter method
correct is :1
Explanations :It can also be done by calling getServletConfig().getInitParaemter, but it is not the
only option.GenericServlet implements ServletConfig so it has all its methods.
------------------------------------------------------------------------------
Question No :35
Which of the following is the formal parameter's type that the HttpRequest.setDateHeader( ? )
method accepts?
(Choose correct one from multiple below)
1. java.util.Date
2. java.sql.Date
3. int
4. long
correct is :4
Explanations :long
------------------------------------------------------------------------------
Question No :36
Which statements are correct about servlets implementing the SingleThreadModel interfaces
(Choose correct one from multiple below)
1. Only one thread at a time will acces the service method
2. The servlet container may decide to create a pool of the servlet instances
3. both are true
4. none of the above
correct is :1
Explanations :Only one thread at a time will acces the service method
------------------------------------------------------------------------------
Question No :37
Which of the following statements about timeouts are correct?
(Choose correct one from multiple below)
1. If no session-config is specified and no maxInactiveInterval is spcecified the servlet container
sets the default timeout.
2. In cookies the maxAge is specified in seconds and a value of zero means cookie deletion
3. In session-config element the timeout is specified in minutes
4. All of the above
correct is :4
Explanations :If no session-config is specified and no maxInactiveInterval is spcecified the servlet
container sets the default timeout.
In cookies the maxAge is specified in seconds and a value of zero means cookie deletion.
In session-config element the timeout is specified in minutes
------------------------------------------------------------------------------
Question No :38
Which statements are correct?
(Choose correct one from multiple below)
1. HttpServlet.init() throws ServletException
2. HttpServlet.service() thrwos ServletException and IOException
3. HttpServlet.destroy() throws ServletException
4. 1 and 2
correct is :4
Explanations :HttpServlet.init() throws ServletException
HttpServlet.service() thrwos ServletException and IOException
destroy throws nothing and all doPost/doGet throws ServletException and IOException.
------------------------------------------------------------------------------
Question No :39
What is the return type of the getLastModified method of HttpServlet?
(Choose correct one from multiple below)
1. java.util.Date
2. java.sql.Date.
3. int.
4. long
correct is :4
Explanations :long
------------------------------------------------------------------------------
Question No :40
Which statements are correct about load-on-startup elements
(Choose correct one from multiple below)
1. It must be an integer
2. Serveral servlets can have the same value for this element
3. If it is 0 it will be loaded at deployment time
4. All of the above
correct is :4
Explanations :It must be an integer.
Serveral servlets can have the same value for this element.
If it is 0 it will be loaded at deployment time.
------------------------------------------------------------------------------