First Test
First Test
First Test
Which
of the following is the best place to do this?
A)constructor b)init c)service
2) If you dont want to make servlet multi-threaded implement
a)Runnable b)SingleThreadModel c)Servlet
3) How does one acquire the object implementing RequestDispatcher interface?
a) Using getRequestDispatcher() method of RequestDispatcher interface
b) Using getRequestDispatcher() method of ServletContext
interface
c) Using getRequestDispatcher() method of HttpSession
4) Once a Servlet is initialized, how do you get the initialization parameters ?
(a) Initialization parameters will not be stored
(b) They will be stored in instance variables
(c) using config.getInitParameters()
5) Which of the following is true ?
(a) Unlimited data transfer can be done using POST method
(b) Data is visible in Browser URL when using POST method
(c) When large amounts of data transfer is to be done, GET method is used.
6) Which of the following statements are true? [Check all correct answers]
A) Local variables are considered thread-safe.
B) Class variables are not considered thread-safe.
C) Class variables are considered thread-safe if the servlet
uses the single thread model.
D) Instance variables are considered thread-safe
if the servlet uses the single thread model.
7) Select all correct statements
a) forward is faster than sendRedirect
b) forwarding page can pass response to client
c) forwarded page can pass response to client
d) includer page can pass response to
client
e) included page can pass response to
client
8) The method gets executed as soon as servlet gets loaded in web server
a)destroy b)service c)init
9) A remote method must throw RemoteException
a)False
b) True
10) Return Type as well as Arguments of a remote method must be of Serialized Type
a)True b)False
13) The total no.of columns, their headings,column types etc. can be displayed with
the object of
a) ResultSet b)ResultSetMetaData c) DriverManager
c)
36) Name the class that includes the getSession method that is used to get the
HttpSession object.
a)HttpServletRequest
b)HttpServletResponse
c)SessionContext
d)SessionConfig
37) Which of the following are correct statements. Select the two correct answers.
a) The getRequestDispatcher method of ServletContext class takes the
full path of the servlet, whereas the getRequestDispatcher method of
HttpServletRequest class takes the path of the servlet relative to the
ServletContext.
B)The include method defined in the RequestDispatcher class can
be used to access one servlet from another. But it can be invoked only if
no output has been sent to the server.
c)The getRequestDispatcher(String URL) is defined in both
ServletContext and HttpServletRequest method
d)The getNamedDispatcher(String) defined in HttpServletRequest
class takes the name of the servlet and returns an object of
RequestDispatcher class.
38) Which method would you override from the abstract class HttpServlet to handle
HTTP POST requests?
A) protected void doPost(HttpServletRequest req,
HttpServletResponse resp) b) public void doPost(HttpServletRequest req,
HttpServletResponse resp)
c) protected void doPost(ServletRequest req,
ServletResponse resp)
d) public void doPost(ServletRequest req,
ServletResponse resp)
e) None of the above
39) What will be the output when you compile and execute the following
servlet?
1.
public class PrinterServlet extends HttpServlet {
2.
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
3.
throws ServletException, IOException {
4.
PrintWriter pw = req.getWriter();
5.
pw.println ("New York");
6.
}
7.
}
40) What statement do you need to insert at line 4 of the AnimalServlet to pick up all
selected animals in the form?
<form
action="/scwcd/servlet/com.baboon.scwcd.servletmodel.AnimalServlet"
method="POST">
<select name="animals" size="3" multiple>
<option value="TIGER">Tiger</option>
<option value="ELEPHANT">Elephant</option>
<option value="LION">Lion</option>
</select>
<input type="submit" value="Search">
</form>
1.
public class AnimalServlet extends HttpServlet {
2.
protected void doPost(HttpServletRequest req,
HttpServletResponse resp)
3.
throws ServletException, IOException {
4.
// insert code here
5.
}
6.
}
41) What would be the output in your browser when you invoke the servlet-code with the
following URL:
http://localhost/servlet/com.baboon.servletmodel.TestParamServlet?Param=10
1.
2.
3.
4.
5.
6.
7.
8.
9.
package com.baboon.servletmodel;
public class TestParamServlet extends HttpServlet {
protected void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException
{
resp.getWriter().println(req.getParameter("param"));
}
}
a)Code compiles, the output is a blank page with the value 10 printed out.
B) Code compiles, the container returns a status stating that doGet is not
supported.
C) Code compiles, the output is a blank page with null printed out.
D) Code failed compilation, exception IOException is not caught.
E) Code compiles, stacktrace is printed out in browser.
42) What is the output when you try to invoke the servlet defined below with the
following URL from the address line from your browser:
http://localhost/servlet/com.baboon.scwcd.servletmodel.TestParamServlet?Param=10
1.
package com.baboon.scwcd.servletmodel;
2.
public class TestParamServlet extends HttpServlet {
3.
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
4.
throws ServletException, IOException {
5.
resp.getWriter().println (req.getParameter("param"));
6.
}
7.
}
a) Code compiles, a blank page is displayed with the value 10 printed out.
B) Code compiles, a blank page with the value null is printed
out.
C) Code compiles, a blank page is displayed.
D) Code compiles, stack trace is printed out,
NullPointerException
e) None of the above
a) 0 minutes.
B) 0 seconds.
C) The session is never invalidated.
D) 30 minutes.
E) The default session timeout interval is container specific
45) Which type of event object is received by an object that implements
HttpSessionAttributeListener when an object is added to, removed from or replaced in a
session?
a) javax.servlet.http.HttpSessionEvent
b) javax.servlet.http.HttpSessionAttributeEvent
c) javax.servlet.http.HttpSessionBindingEvent
d)javax.servlet.http.HttpHttpSessionAttributeListener
e)javax.servlet.http.HttpSessionBindingListener
a) More than one error page declaration can be configured in the web application's
deployment descriptor.
B) Error page declarations with different error codes can be associated to the
same location.
C) wehavemoved.jsp is called by the servlet container if a servlet invokes
setStatus(301) on a response object.
d) errorhandler.jsp is called by the servlet container if either an internal error is
encountered by the servlet container or a java.lang.Throwable exception is propagrated to
the container.
E) The value of the location must have a leading '/'.
java.io.IOException;
javax.servlet.*;
javax.servlet.http.*;
com.pleasanthotel.RoomUnavailableException;
a) <error-page>
<error-code>500</error-code>
<location>/intervalservererrorhandler.jsp</location>
</error-page>
b) <error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/servletexceptionhandler.jsp</location>
</error-page>
c) <error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>servletexceptionhandler.jsp</location>
</error-page>
d) <error-page>
<exception-type>com.pleasanthotel.RoomUnavailableException</exception-type>
<location>/roomunavailableexceptionhandler.jsp</location>
</error-page>
e) <error-page>
<exception-type>com.pleasanthotel.RoomUnavailableException</exception-type>
<location>roomunavailableexceptionhandler.jsp</location>
</error-page>
52) Select the correct statements about the following code. [Check all
correct answers]
1.
import javax.servlet.http.*;
2.
public class RainbowServlet extends HttpServlet {
3.
private int numColours;
4.
public void doGet(HttpServletRequest req, HttpServletResponse
res) {
5.
String outerColour = "Red";
6.
}
7.
}
b) javax.servlet.SingleThreaded
d) javax.servlet.ThreadSafe
e) ServletConfig.getInitParameterNames()
57) Which method can you use to obtain parameters mentioned in the deployment
descriptor of your web-application?
a) String getInitParameter(String name);
b) String getParameter(String name);
c) String getInitAttribute(String name);
d) String getAttribute(String name);
e) String getResource(String name);
58) Type 4 database driver, also known as thin driver
1. True
2. False
59) Which one of the following is the correct sequence of opening a result set.
1. Create Statement, create connection, open result set.
2. Create Connection, create statement, open result set
3. Load driver, open connection, create statement, open result set.
4. All of the above.
60) Which interface defines the following method in the servlet API?
public void service (ServletRequest request, ServletResponse response)
1. javax.servlet.Servlet
2. javax.servlet.GenericServlet
3. javax.servlet.HttpServlet
4. javax.servlet.http.HttpSession
61) Read the following code segment
<form action="/scwcd/servlet/com.baboon.scwcd.servletmodel.AnimalServlet" method="POST">
<select name="animals" size="3" multiple>
<option value="TIGER">Tiger</option>
<option value="ELEPHANT"> Elephant
</option>
<option value="LION">Lion</option>
</select>
<input type="submit" value="Search">
</form>
1. public class AnimalServlet extends HttpServlet {
2. protected void doPost(HttpServletRequest req, HttpServletResponse resp)
3. throws ServletException, IOException {
4. // insert code here
5. }
6. }
What statement do you need to insert at line 4 of the AnimalServlet to pick up all selected animals in
the form?
1. String animals= req.getParameter("animals");
2. String[] animals = req.getParameterValues("animals");
3. String[] animals = req.getParameterNames("animals");
4. None of the above
62) Which of the following actions will cause a session to be expunged( wiped out) in a web
application?
1. Navigating to a different web site or web application
2. Closing the web browser.
3. The client does not send a request to the web application for a length of time that exceeds
the session timeout value of the associated session object in the application.
4. All of the above.
63) You have created a Listener called AccountApplicationListener that receives events when the
context of the web-application "account" is created or destroyed. How would you define this in
your deployment descriptor?
1. <listener>
com.cdac.acts.AccountApplicationListener
</listener>
2. <listener>
<listener-class>com.cdac.acts.AccountApplicationListener </listener-class>
</listener>
3. <listener-class>com.cdac.acts.AccountApplicationListener</listener-class>
4. <web-app name="account">
<listener-class>com.cdac.acts.AccountApplicationListener</listener-class>
</web-app>
64) Which interface of the Servlet API's defines methods to extract form parameters from the HTTP
request?
1. HttpServletRequest
2. ServletRequest
3. Servlet
4. HttpServletResponse
65) Which statement can be inserted in a Servlet to forward the request to http://www.cdac.in, outside
the current domain?
1. resp.encodeRedirectURL("http://www.cdac.in");
2. resp.sendRedirect(resp.encodeRedirectURL("http://www.cdac.in "));
3. resp.sendRedirect(HttpServletResponse.SC_MOVED_PERMANENTLY, " http://www.cdac.in ");
4. getServletContext().getRequestDispatcher("http://www.cdac.in).forward(req,resp);
66) A _______ object is used to submit a query to database.
1. Connection
2. ResultSet
3. Statement
4. Any of the above
67) ________ allows Java Objects running on separate computer to communicate with one another
via remote method calls.
1. RMI
2. Threads
3. Tag libraries
4. None of the above
68) You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make
sure that the user continues in the same session. How do you do that?
1. By calling the method with an absolute path as the argument
2. By enconding the path with HttpServletResponse.endcodeURL method
3. By enconding the path with HttpServletResponse.endcodeRedirectURL method
1. Distributed Application.
2. The ability to examine the encapsulated data of a class.
3. Remote method invocation.
4. The ability transform the state of an object into bits and resurrect a copy of the object from
those bits.
74) By using Java System Property, one can load the driver into the memory.
1. True
2. False