C) You Are User No 3 To Visit This Site
C) You Are User No 3 To Visit This Site
1) What is the output of the following code if the user types the url as
http://localhost:8080/emp_details/servlet/EmployeeDetails and browser is refreshed
three times?
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
a) ("<B>You are user no. " + i +" to visit this site.</B><BR><BR>”);
b) You are user no 1 to visit this site
c) You are user no 3 to visit this site
d) Exception is shown
4) ------ is the approach to keep only a few connections that are shared among data
access logic elements
a) Connection pooling
b) DAO pattern
c) Struts framework
d) Filtering of servlets
5) Which of the following is the correct syntax for locating a datasource using JNDI
a) Context c= InitialContext();
If(c==null)
{ throw new RuntimeException(“JNDI context could not be found”); }
ds=(DataSource) c.lookup(“java:comp/env/jdbc/myDB”);
If(ds==null)
{ throw new RuntimeException(“DataSource could not be found”);}
b) Context c=new InitialContext();
If(c==null)
{ throw new RuntimeException(“JNDI context could not be found”); }
ds=(DataSource)lookup(“java:comp/env/jdbc/myDB”);
If(ds==null)
{ throw new RuntimeException(“DataSource could not be found”);}
c) Context c=new InitialContext();
If(c==null)
{ throw new RuntimeException(“JNDI context could not be found”); }
ds= c (“java:comp/env/jdbc/myDB”);
If(ds==null)
{ throw new RuntimeException(“DataSource could not be found”);}
d) Context c=new InitialContext();
If(c==null)
{ throw new RuntimeException(“JNDI context could not be found”); }
ds=(DataSource) c.lookup(“java:comp/env/jdbc/myDB”);
If(ds==null)
{ throw new RuntimeException(“DataSource could not be found”);}
7) which is the correct syntax for configuring a datasource and JNDI in web.xml
file?
a) <resource-ref>
<description>
This defines a JNDI resource reference for
java:comp/env/jdbc/leagueDB DataSource which
is formally declared in the domain.xml.
</description>
<res-ref-name>jdbc/leagueDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
b) <resource-ref>
<description>
This defines a JNDI resource reference for
java:comp/env/jdbc/leagueDB DataSource which
is formally declared in the domain.xml.
<res-ref-name>jdbc/leagueDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</description>
c) <resource-ref>
<description>
This defines a JNDI resource reference for
java:comp/env/jdbc/leagueDB DataSource which
is formally declared in the domain.xml.
</description>
<res-ref-name>jdbc/leagueDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
d) <resource-ref>
<description>
This defines a JNDI resource reference for
java:comp/env/jdbc/leagueDB DataSource which
is formally declared in the domain.xml.
</description>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
9) when filter is called which of the following method is called by container in turn?
a) init()
b) doFilter()
c) destroy()
d) none of the above
10) Which method is invoked only once in the life cycle of a servlet?
a. init()
b. doPost()
c. service()
d. doGet()
12) Identify the method called by the Web container after creating a servlet
instance.
a. init()
b. service()
c. start()
d. destroy()
14) Identify the method that sends user information as query string
appended to the URL.
a. GET
b. POST
c. HEAD
d. DELETE
15) Which of the following method does the container calls to allow a servlet to release
all resources it is holding?
a. service()
b. destroy()
c. init()
d. doGet()
17) Which of the following element of the deployment descriptor specifies the
name of the servlet class file?
a. <servlet>
b. <servlet-class>
c. <servlet-name>
d. <display-name>
20) A servlet, TestServlet is deployed in the J2EE application server installed in your
computer with the context root as testctx. Which of the following URL will
you specify to access the servlet?
a. http://localhost:8080/testctx/TestServlet
b. http://localhost:8080/testctx/servlet/TestServlet
c. http://localhost:8080/testctx/servlet/TestServlet.class
d. http://localhost:8080/servlet/testctx/TestServlet
21) You need to create a listener class to receive notification from the container when the
servlet context is initialized. Which of the following interface will you
implement in your listener class to receive the notification?
a. ServletContextListener.
b. ServletContextAtributeListener.
c. ServletContext.
d. Servlet.
22) Which of the following object does the container pass to the init() method of
the servlet?
a. ServletContext.
b. ServletRequest
c. ServletConfig
d. ServletResponse
23) Identify the sequence of servlet methods that are invoked when a servlet is accessed
for the first time?
a. init(), doPost(), service(), destroy()
b. service(), init(), destroy()
c. init(), doGet(), service(), destroy()
d. init(), service(), doGet()/doPost(), destroy()
24) Which of the following statement regarding the HTTP POST method is true?
a. Allows sending unlimited length of data as a part of HTTP request body.
b. Allows creation of bookmarks.
c. Uses simple query strings.
d. POST is the default method unless explicitly specified.
25) The getRemoteAddr() method of the ServletRequest interface returns a String that
represents:
a. The name of the computer from which the request is sent.
b. The IP address of the computer from which the request is sent.
c. The name of the computer, where the servlet is running.
d. The IP address of the computer where the servlet is running.
26) Which interface is used to log messages to the application server log file?
a. HttpServletRequest
b. ServletResponse
c. HttpSession
d. ServletContext
28) Which event is generated when there is any change in the attribute of the session
object?
a. javax.servlet.http.HttpSessionEvent
b. javax.servlet.http.HttpSessionActivationEvent
c. javax.servlet.http.HttpSessionAttributeEvent
d. javax.servlet.http.HttpSessionBindingEvent
31. The setMaxAge(int expiry) method defined in the Cookie class sets:
a) The maximum age of cookies in milliseconds
b) The maximum age of cookies in seconds
c) The maximum age of cookies in minutes
d) The maximum age of cookies in hours
33. Which one of the following is not a technique to maintain the state of an end user
visiting multiple pages of a Web site?
a. Cookies
b. Hidden Form Fields
c. Servlet Session APIs
d. Request Dispatcher
34Which session management technique does not transfer session information between a
client and server?
a. URL rewriting
b. Cookies
c. Servlet Session API
d. Hidden Fields
35. select the correct option that specifies the two exception classes that handle servlet-
related exceptions:
a. IOException, ServletException
b. ServletException, UnavailableException
c. UnavailableException, IOException
d. IOException, EOFException
36. Name the class that includes the getSession() method that is used to get the
HttpSession object.
a. HttpServletRequest
b. HttpServletResponse
c. ServletContext
d. ServletConfig
37. Which of the following interfaces can you implement in your servlet to ensure that
your servlet instance handles only a single request at a time:
a. HttpServlet
b. GenericServlet
c. SingleThreadModel
d. Runnable
38. Select the correct code snippet that demonstrates retrieving a value, user from a
Cookie object.
a. Cookie ck[] = req.getCookies();
If (ck!=null)
{
for (int i=0; i<ck.length; i++)
{
if (ck[i].getName().equals("user"))
username = ck[i].getValue();
}}
b. Cookie ck = req.getCookies();
if (ck!=null)
{
for (int i=0; i<ck.length; i++)
{
if (ck[i].getName().equals("user"))
username = ck[i].getValue();
}
}
c. Cookie ck[] = req.getCookie();
if (ck!=null)
{
for (int i=0; i<ck.length; i++)
{
if (ck[i].getName().equals("user"))
username = ck[i].getValue();
}
}
d. Cookie ck = req.getCookies();
if (ck!=null)
{
for (int i=0; i<ck.length; i++)
{
if (ck[i].getCookieName().equals("user"))
username = ck[i].getCookieValue();
}
}
39. Which of the following deployment descriptor elements specifies the session
timeout value to 30 minutes:
a. <session-timeout>30</session-timeout>
b. <session-timeout>30*60</session-timeout>
c. <session-timeout>30*60*60</session-timeout>
d. <session-timeout>30*1000<session-timeout>
43. Which method is not included in the life cycle method of a Servlet filter?
a) init()
b) start()
c) doFilter()
d) destroy()
48)