Smaple Questions Advance Java-Servlets
Smaple Questions Advance Java-Servlets
1. Which one of the following HTTP methods is commonly used to test the validity of a hyperlink
when you do not want (or need) to actually retrieve the content of the link, as the latest version
is already available?
a) CHECK
b) TEST
c) PUT
d) GET
e) HEAD
2. Which one of the following methods will be invoked when a ServletContext is destroyed?
a) contextDestroyed() of javax.servlet.ServletContextListener
b) contextDestroyed() of javax.servlet.HttpServletContextListener
c) destroy() of javax.servlet.GenericServlet
d) contextDestroyed() of javax.servlet.http.HttpServletContextListener
e) contextDestroyed() of javax.servlet.http.HttpSessionListener
import javax.servlet.*;
public class MyListener implements ServletContextAttributeListener
{
public void attributeAdded(ServletContextAttributeEvent scab)
{
System.out.println("attribute added");
}
public void attributeRemoved(ServletContextAttributeEvent scab)
{
System.out.println("attribute removed");
}
}
Which one of the following statements about the above class is correct?
5.You want to write Servlet classes for a new web protocol of yours that you have developed.
Which one of the classes from the following would you extend your servlets from?
a) HttpServlet
b) GenericServlet
c) Servlet
d) AbstractServlet
6.Which one of the following methods would you use to put the session id into the URL to
support sessions using URL rewriting?
a) rewriteURL() of HttpServletResponse
b) rewriteURL() of HttpServlet
c) encodeURL() of HttpServletRequest
d) encodeURL() of HttpServletResponse
e) encodeURL() of HttpServlet
a) The deployment descriptor must be well formed, i.e. every tag every tag must have a
matching closing tag (or be closed with a forward slash)
b) The deployment descriptor contains information on the configuration of servlets in a web
application
c) A single deployment descriptor may be used to configure multiple web applications
d) The deployment descriptor cannot contain comments
e) The deployment descriptor can be edited by the designer
a) A file marked as load-on-startup will be returned as the default from a request to a directory with
no file component.
b) By default if a directory contains a file called welcome.jsp it will be returned from a request where
no file name is specified.
c) Only a jsp file can be marked as a welcome file, not a servlet
d) A file or a jsp can be marked as a welcome file within the deployment descriptor
e) A jsp file will be placed in the source packages folder
10.Which one of the following options would initialize a stream for sending text to a browser?
11.Which one of the following is the correct way of retrieving the value of the "User-Agent"
header value from the request from the service method( eg: doPost() )?
a) String userAgent=request.getParameter("User-Agent");
b) String userAgent=request.getHeader("User-Agent");
c) String userAgent=request.getRequestHeader("User-Agent");
d) String userAgent=getServletContext().getInitParameter("User-Agent");
12.Which one of the following HTTP methods is used to show the client what the server is
receiving?
a) GET
b) TRACE
c) RETURN
d) OPTIONS
13.Which one of the following is the correct way of setting the header named "CONTENT-
LENGTH" in the HttpServletResponse object?
a) response.setHeader(CONTENT-LENGTH,"numBytes");
b) response.setHeader(1024);
c) response.setHeader("CONTENT-LENGTH", "numBytes");
d) response.setHeader("CONTENT-LENGTH",1024);
14.Which one of the following servlet code fragments gets a binary stream for writing an image
or other binary type to the HttpServletResponse?
a) java.io.PrintWriter out=response.getWriter();
b) ServletOutputStream out=response.getOutputStream();
c) java.io.PrintWriter out=new PrintWriter(response.getWriter());
d) ServletOutputStream out=response.getBinaryStream();
15. Which three of the following methods are declared in HttpServletRequest as opposed to in
ServletRequest?
a) getMethod()
b) getHeader()
c) getCookies()
d) getInputStream()
e) getParameterName()
16.Which one of the following is the abstract method in the HttpServlet abstract class?
a) service()
b) doGet()
c) doPost()
d) No abstract methods
17. Which one of the following HttpServletResponse is used to redirect an HTTP request to
another URL?
a) sendURL()
b) redirectURL()
c) redirecthttp()
d) sendRedirect()
20. When is it not possible to call the sendRedirect() method of response object?
Select one correct answer from the following.
21. Which one of the following is a valid tag for configuring a listener class?
a) <contextlistener>
<listener-class>mypackage.SomeListener</listener-class>
</contextlistener>
b) <listener>
<listener-class>mypackage.SomeListener</listener-class>
</listener>
c) <context-listener>
<listener-class>mypackage.SomeListener</listener-class>
</context-listener>
d) <listener>
<class>mypackage.SomeListener</class>
</listener>
22. Which two of the following statements are true?
23. Which one of the following statements is true about the Web Application
DeploymentDescriptor?
a) There cannot be leading nor trailing spaces for PCDATA within text nodes
b) The servlet container must ensure that role-names in auth-constraint are defined in security-role
element
c) URI paths specified are assumed to be URL decoded form
d) Web Application DD cannot be edited by a deployer
24. Which one of the following statements is false about the method log?
26. Which two of the following are mandatory elements of the web-resource-collection element?
a) web-resource-name
b) url-pattern
c) http-method
d) auth-constraint
e) description
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyFirstServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
res.setContentType("text/html");
}
Which one of the following will happen because of the above entry in the Deployment
Descriptor(DD)?
a) Log all session information as they occur
b) Provide a Log Servlet for the entire application
c) Create a listener as defined by the com.javarich.LogListener class.
d) The webapp will not be loaded due to a parse exception of the DD
e) <Listener> must come under <servlet>tag
30. Your servlet can specify a different session timeout than the one defined in the Deployment
Descriptor.
Which one of the following methods need to be called to achieve this?
a) HttpServlet#setSessionTimeout(int interval)
b) HttpSession#setMaxInactiveInterval(int seconds)
c) HttpSession#setSessionTimeout(int interval)
d) HttpSession#setMinInactiveInterval(int interval)
e) The timeout in deployment descriptor cannot be changed.
31. What will happen when you attempt to compile and run the following code (assuming
menu.jsp is available)?
package com.evaluvate;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
32. Consider the following code for the init() method of a servlet:
public void init()
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// 1 Get DBURL here
theConnection = DriverManager.getConnection(dbUrl, "admin", "admin");
}
Which two of the following LOCs "may" correctly retrieve the DBURL parameter at //1?
a) servletcontext.getInitParameter("DBURL");
b) this.getParameter("DBURL");
c) servletcontext.getParameter("DBURL");
d) this.getContextParameter("DBURL");
e) this.getInitParameter("DBURL");
33. Following is the code for doGet() and doPost() method of TestServlet:
Assuming the user changes none of the default setting s and presses SUBMIT, what will be the
servlet output in the response?
a) First:Second:Third
b) First:Second:Second
c) First:Third:Third
d) First:First:Second
e) No response-servlet will not compile
35. What is the maximum number of parameters that can be forwarded to the servlet from the
following HTML form?
<html>
<body>
<form action=”ParamServlet” method=”get”.
<select name=”Languages” size=”3” multiple>
<option value=”JAVA” selected>Java</option>
<option value=”CSHARP” selected>C#</option>
<option value=”C” selected>C</option>
<option value=”CPLUS” selected>C++</option>
<option value=”PASCAL” selected>pascal</option>
<option value=”ADA” selected>Ada</option>
</select>
<input type=”submit” name=”button”/>
</form>
</body>
</html>
a) If there are no request headers present in the request for the given header name.
b) If there are multiple headers for the given header name
c) If the container disallows access to the header information
d) If there are multiple values for the given header name
e) There is no such method on HttpServletRequest
37. Which three of the following are likely to be found as request header fields?
a) Accept
b) WWW-Authenticate
c) Accept-Language
d) From
e) Client-Agent
38. What will be the outcome of running the following servlet code?
Long date=request.getDateHeader(‘Host”);
response.setContentType(“text/plain”);
response.getWriter().write(“”+date);
39. What will be the outcome of attempting to run the following servlet code?
String[] values=request.getHeaders(“Joy”);
Response.setContentType(“text/plain”);
Response.getWriter().write(values[0]);
a) IllegalArgumentException
b) NumberFormatException
c) Will not run: 1 compilation error.
d) Will not run:2 compilation errors.
e) Null written to the response
a) Get
b) Post
c) Trace
d) Head
e) Options
41.Which two of the following circumstances will cause a servlet instance’s destroy() method to
be never called?
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
a) 30 minutes
b) 40 minutes
c) Gives illegalStateException
d) None of the listed options
43.Which one of the following is a valid life cycle event listener interface but is NOT configured
in the web.xml?
a) HttpSessionListener
b) SessionActivationListener
c) HttpSessionBindingListener
d) ContextAttributeListener
e) SessionAttributeListener
package com.evaluation;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ReqD extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext sc = this.getServletContext();
RequestDispatcher dis = sc.getRequestDispatcher("/menu.jsp");
if (dis != null){
dis.include(request, response);
}
PrintWriter out = response.getWriter();
out.print("Output after menu.jsp");
}
}
Which one of the following will be the correct outcome when the above is executed?
a) Every (non distributed) web application has only one instance of ServletContext
b) Every instance of HttpServlet has only one instance of ServletContext
c) The ServletContext object is retrieved via the getServletContext method of ServletConfig
d) The ServletConfig object is retrieved via the getServletConfig method of ServletContext
a) HttpServletResponse
b) HttpSession
c) HttpServlet
d) ServletContext
e) ServletConfig
50.Which two of the following statements are true?
a) A request attribute will be visible to all subsequent request from the same client
b) A session attribute will, by default be visible to all subsequent requests from the same
client
c) Attributes are stored with the data type of Object
d) ServletContext attributes are only visible within the same servlet.
e) ServletCofig attributes are visible to all subsequent request for the same client
a) <servlet>
<servlet-name>HelloGeneric</servlet-name>
<servlet-class>HelloGeneric</servlet-class>
<init-param>
<param-name>count</param-name>
<param-value>13</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloGeneric</servlet-name>
<url-pattern>/HelloGeneric</url-pattern>
</servlet-mapping>
b) <servlet>
<init-param>
<param-name>count</param-name>
<param-value>13</param-value>
</init-param>
<servlet-name>HelloGeneric</servlet-name>
<servlet-class>HelloGeneric</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloGeneric</servlet-name>
<url-pattern>/HelloGeneric</url-pattern>
</servlet-mapping>
c) <servlet>
<servlet-name>HelloGeneric</servlet-name>
<init-param>
<param-name>count</param-name>
<param-value>13</param-value>
</init-param>
<servlet-class>HelloGeneric</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloGeneric</servlet-name>
<url-pattern>/HelloGeneric</url-pattern>
</servlet-mapping>
d) <servlet>
<servlet-name>HelloGeneric</servlet-name>
<servlet-class>HelloGeneric</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloGeneric</servlet-name>
<url-pattern>/HelloGeneric</url-pattern>
<init-param>
<param-name>count</param-name>
<param-value>13</param-value>
</init-param>
</servlet-mapping>
e) <init-param>
<param-name>count</param-name>
<param-value>13</param-value>
</init-param>
<servlet>
<servlet-name>HelloGeneric</servlet-name>
<servlet-class>HelloGeneric</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloGeneric</servlet-name>
<url-pattern>/HelloGeneric</url-pattern>
</servlet-mapping>
53. Which two of the following statements are correct about the HttpServletResponse's buffer?
a) You can specify its size with the method setBufferSize with either a number ending with kb or the
word none
b) If you use setBufferSize method after any content has been written the buffer won't be changed
c) reset will clear uncommitted data including headers and status line
d) resetBuffer won't clear headers nor status line
e) default buffer size will be 12kb
55. Which one of the following statements is correct about the way a servlet can access its
initialization parameters?
a) By simply calling getInitParameter from any of the servlets methods (for example doGet)
b) It must be done only by calling getServletConfig().getInitParaemter
c) It can only be done by overriding the method init(ServletConfig config)
d) It can be done by calling getServletContext().getInitParameter method
56. Assume that the following servlet mapping is defined in the deployment descriptor of a web
application:
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
a) WEB-INF
b) WEB-INF/classes
c) WEB-INF/lib
d) WEB-INF/jars
e) WEB-INF/classes/com/abc
58.Consider the following code for the doGet() method:
Which one of the following lines can be inserted at //1 so that the above code does NOT throw
any exception?
a) if ( ! res.isSent() )
b) if ( ! res.isCommitted() )
c) if ( ! res.isDone() )
d) if ( ! res.isFlushed() )
e) if ( ! res.flush() )
59. What is printed as output on the server console when the following servlet program runs for
the first time?
1.import java.io.IOException;
2.import java.io.PrintWriter;
3.mport javax.servlet.*;
4.public class HelloGeneric extends GenericServlet {
5.public HelloGeneric() {
6.super();
7.System.out.println("constructor ");
8.}
9.public void init() throws ServletException {
10. super.init();
11. System.out.println("init ");
12.}
13.public void init(ServletConfig arg0) throws ServletException {
14.super.init(arg0);
15.System.out.println("init with ServletConfig ");
16.}
17.public void service(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
18.System.out.println(“service method ”);
19.}
20.}
Select one answer from the following.
You want the userid parameter to be available only to the requests that come from the same
user.
Which one of the following lines would you insert at //1?
a) session.setAttribute("userid", userid);
b) req.setAttribute("userid", userid);
c) ctx.addAttribute("userid", userid);
d) session.addAttribute("userid", userid);
e) this.addParameter("userid", userid);
<servlet-mapping>
<servlet-name>goldie</servlet-name>
<url-pattern>*.g</url-pattern>
</servlet-mapping>
Which two of the following requests will be serviced by the servlet named 'goldie'?
a) http://abcinc.com/g
b) http://abcinc.com/goldie/temp.g
c) http://abcinc.com/servlet/goldie/temp
d) http://abcinc.com/a/b/c/temp.g
e) http://abcinc.com/goldie/empt.g
62. What are the implications of using the HTTP GET method for a form submission?
Select three answers from the following.
<html><body>
<a href="/servlet/HelloServlet">POST</a>
</body></html>
Which one of the following methods of HelloServlet will be invoked when the hyperlink
displayed by the above page is clicked?
a) doGet
b) doPost
c) doForm
d) doHref
e) serviceGet
64.Which one of the following lines would initialize the out variable for sending a Microsoft Word
file to the browser?
65. Which two of the following methods would you use to retrieve header values from a request?
a) getHeader() of ServletRequest
b) getHeaderValue() of ServletRequest
c) getHeader() of HttpServletRequest
d) getHeaders() of ServletRequest
e) getHeaders() of HttpServletRequest
66. Assuming that the Servlet Container has just called the destroy() method of a servlet
instance,
which two of the following statements are correct?
a) Any resources that this servlet might hold have been released.
b) The servlet container time out has exceeded for this servlet instance.
c) The init() method has been called on this instance.
d) None of the requests can EVER be serviced by this instance.
e) All threads created by this servlet are done.
a) The init method is called each time a Servlet service method runs
b) The init method is called by the container when it is placed into service
c) The init method cannot be overridden because it is marked as final
d) When a container shuts down it will call the undeploy method of running Servlets
e) When a container shuts down it will call the destroy method of running Servlets
68.Which one of the following statements is true? (given that webapp is the root of the web
application)
a) To be able to directly access a servlet the servlet-name must have a matching servlet-
mapping
b) The init-param tag may contain java code between its opening and closing brackets
c) The welcome-file tag can mark a servlet as the default item that is returned from a url
d) The welcome-file tag must point to a servlet called welcome
e) The error-page tag must point to an html or JSP page, not a servlet.
70.You have configured your web application deployment descriptor to make some initialization
parameters available to every servlet.
Which one of the following will retrieve those parameters?
if(userId == null)
else
}
}
The data should be sent to the client only if loginUser() returns a non null userid, otherwise a
status of SC_FORBIDDEN should be sent.
What can be placed at //1 to fulfill this requirement?
Select three answers from the following.
a) req.getRequestDispatcher("errorpage.jsp").dispatch(req, res,
HttpServletResponse.SC_FORBIDDEN)
b) throw new ServletException(HttpServletResponse.SC_FORBIDDEN)
c) res.setStatus(HttpServletResponse.SC_FORBIDDEN)
d) res.sendError(HttpServletResponse.SC_FORBIDDEN, "You are not authorized.")
e) res.sendError(HttpServletResponse.SC_FORBIDDEN)
74. Which two of the following are sensible ways of sending an error page to the client in case of
a business exception that extends from java.lang.Exception?
a) Catch the exception and use RequestDispatcher to forward the request to the error page
b) Do not catch the exception and define the 'exception to error-page' mapping in web.xml
c) Catch the exception, wrap it into ServletException and define the 'business exception to
error-page' mapping in web.xml
d) Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page'
mapping in web.xml
e) Do not do anything, the servlet container will automatically send a default error page.
75. Identify correct statements about session management from the list below.
(Select two answers)
76.What are the possible outcome from executing the doGet method in Toyservlet given below?
Which of the following statements can be inserted at //1 so that logMsg may be entered into the
servlet log file?
(Select three answers)
a) log(logMsg);
b) req(logMsg);
c) getServletConfig().log(logMsg);
d) getServletContext().log(logMsg);
e) getServletConfig().getServletContext().log(logMsg);
79.Which three of the following codes represent internal dispatch to servlet requests?
a) <filter-mapping>
<filter-name>All Dispatch Filter</filter-name>
<servlet-name>*</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
b) <filter-mapping>
<filter-name>All Dispatch Filter</filter-name>
<servlet-name>*</servlet-name>
<dispatcher>ERROR</dispatcher></filter-mapping>
c) <filter-mapping>
<filter-name>All Dispatch Filter</filter-name>
<servlet-name>*</servlet-name>
<dispatcher>RESPONSE</dispatcher>
</filter-mapping>
d) <filter-mapping>
<filter-name>All Dispatch Filter</filter-name>
<servlet-name>*</servlet-name>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
e) <filter-mapping>
<filter-name>All Dispatch Filter</filter-name>
<servlet-name>*</servlet-name>
</filter-mapping>
80.Which two of the following are names of special attributes associated with the dispatching
mechanism?
a) java.servlet.include.servlet_name
b) javax.http.servlet.include.query_name
c) javax.servlet.include.servlet_path
d) javax.servlet.forward.request_url
e) javax.servlet.include.path_info
81. Which two of the following are true statements about sessions?
a) Sessions can span web applications
b) Sessions can be cloned across JVMs
c) Sessions are destroyed only after a predefined period of inactivity
d) Sessions can be set to never time out
e) You can use the deployment descriptor to cause sessions to expire after a set number of
requests.
82.Which one of the following lines of code, in the doPost() method of a servlet, uses the URL
rewriting approach to maintaining sessions?
a) useURLRewriting();
b) out.println(response.rewrite("<a href='/servlet/XServlet'>Click here</a>"));
c) out.println("<a href=' "+request.rewrite("/servlet/XServlet")+" '>Click here</a>"));
d) out.println("<a href=' "+response.encodeURL("/servlet/XServlet")+" '>Click here</a>"));
e) out.println("<a href=' "+request.encodeURL("/servlet/XServlet")+" '>Click here</a>"));
83.Which three of the following elements are allowed in the <filter-mapping> element of the
deployment descriptor?
a) <servlet-name>
b) <filter-class>
c) <dispatcher>
d) <url-pattern>
e) <filter-chain>
84.Rahul is working on a web application. He wants to have a functionality that will enable him
to know if the session the user is using is from cookie or from URL .
86.Which two of the following are true regarding the parameters defined using the <context-
param> element of a deployment descriptor?
a) service()
b) init()
c) doGet
d) all doXXX methods
e) No method as HttpServlet has dummy implementations
91.Which one of the following interfaces or classes is used to retrieve the session associated
with a user?
a) GenericServlet
b) ServletConfig
c) ServletContext
d) HttpServlet
e) HttpServletRequest
93.Which one of the following methods will be invoked on a session attribute that implements
HttpSessionBindingListener when the session is invalidated?
a) sessionDestroyed
b) valueUnbound
c) attributeRemoved
d) sessionInvalidated
e) sessionDeactivated
94.Which one of the following method calls will ensure that a session will never be expunged by
the servlet container?
a) session.setTimeout(0);
b) session.setTimeout(-1);
c) session.setTimeout(Integer.MAX_VALUE);
d) session.setTimeout(Integer.MIN_VALUE);
e) HttpSession.setMaxInactiveInterval(int seconds)
96.Servlets that implement the SingleThreadModel cannot share a single HttpSession Object
across multiple servlets.
State True or False.
a) TRUE
b) FALSE
98.Which one of the following classes is appropriate for monitoring when users sign into the
system and recording it in the log?
a) ApplicationContextAttributeListener
b) HttpSessionListener
c) HttpSessionActivationListener
d) HttpLoginListener
e) ServletContextListener
99.Which one of the following methods would you use to acquire the stream to write binary data
in response to a request to from servlet?
a) getOutputStream() of ServletResponse interface.
b) getOutputStream() of HttpServletResponse interface.
c) getFileOutputStream() of HttpServletResponse interface
d) getWriter() of HttpServletResponse interface
e) getWriter() of ServletResponse interface
101.Which two of the following statements correctly store an object associated with a name at a
place where all the servlets/JSPs of the same webapp participating in a session can use it?
(Assume that request, response, name, value etc. are references to objects of appropriate
types.)
a) request.setAttribute(name, value)
b) response.setAttribute(name, value)
c) request.getSession().setAttribute(name, value)
d) servlet.getServletContext().setAttribute(name, value)
e) request.setParameter(name, value)
102.Which two of the following situations will result in a session getting invalidated?
a) No request is received from the client for longer than the session timeout period
b) The client sends a KILL_SESSION request.
c) The servlet container decides to invalidate a session due to overload
d) The servlet explicitly invalidates the session
e) A user closes the active browser window
105.<web-app>
...
<session-config>
<session-timeout>15</session-timeout>
</session-config>
....
What does the above entry in the Deployment Descriptor cause?
Select one answer from the following.
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/math_error.html</location>
</error-page>
107.Which one of the following method calls creates a binary output stream in a servlet?
a) response.getOutputStream();
b) request.getWriter();
c) request.getOutputStream();
d) response.getWriter();
e) Session.getOutputStream();
108.You have two classes named 'MyServletContextAttributesListener' and
'MyHttpSessionListener' which implement interfaces as suggested by their names.
Which one of the following XML fragments, written directly under the <web-app> tag, correctly
register these classes so that their instances may receive appropriate notifications?
a) <listener>
<listener-class>MyServletContextAttributesListener</listener-class>
<listener-class>MyHttpSessionListener</listener-class>
</listener>
b) <listener-class>MyServletContextAttributesListener</listener-class>
<listener-class>MyHttpSessionListener</listener-class>
c) <listener>
<listener-class>MyServletContextAttributesListener</listener-class>
</listener>
<listener>
<listener-class>MyHttpSessionListener</listener-class>
</listener>
d) <context-listener>
<listener-class>MyServletContextAttributesListener</listener-class>
</context-listener>
<session-listener>
<listener-class>MyHttpSessionListener</listener-class>
</session-listener>
e) <listener>MyServletContextAttributesListener</listener>
<listener>MyHttpSessionListener</listener>
109.Identify three techniques from the following that can be used to implement 'sessions' if the
client browser does not support cookies.
a) Using Http headers.
b) Using https protocol
c) Hidden form fields.
d) URL rewriting
e) It cannot be done without cookie support.
a) Once an ServletRequest attribute has been set, it is visible to all subsequent requests
b) Data in a HttpSession attribute will be available if the web server restarts.
c) Data in the ServletContext can be shared by any servlet of the same web application
d) The getParameter method of HttpSession will retrieve a session attribute
112. Which two of the following statements are true?
a) The doFilter method is always invoked by the container, never within a programmers code
b) A filter can be invoked either through being declared in WEB.XML or explicitly within a
programmers code
c) Filters are associated with a URL via the filter-mapping tag
d) Filters can be initialised via the filter-init-param tag in the deployment descriptor
e) Filters can be initialised via the init-param tag in the deployment descriptor
Which three of the following options will retrieve the HttpSession associated with the request?
(Assume that the session has already been created.)
a) HttpSession session = request.getSession();
b) HttpSession session = HttpSession.getSession(sid);
c) HttpSession session = request.getSession(sid);
d) HttpSession session = request.getSession(true);
e) HttpSession session = request.getSession(false);
118.Which two of the following classes/interfaces provide methods to write messages to a log
file?
a) GenericServlet
b) ServletRequest
c) HttpServletRequest
d) ServletContext
e) Only GenericServlet
119.Which one of the following gives the correct return type for ServletContext.getResource()
and ServletContext.getResourceAsStream() methods?
a) java.io.Resource and java.io.InputStream
b) java.io.Resource and java.io.BufferedInputStream
c) java.net.URL and java.io.InputStream
d) java.io.File and java.io.InputStream
e) java.net.URL and java.io.FileInputStream
120.Which one of the following HTTP protocol methods is eligible to produce unintended side
effects upon multiple identical invocations beyond those caused by single invocation?
a) GET
b) POST
c) PUT
d) OPTIONS
e) HEAD
121.Which one of the following can be used to explicitly expunge the session object?
a) You cannot. It can only be expunged automatically after session timeout expires.
b) By calling invalidate() on session object.
c) By calling expunge() on session object.
d) By calling delete() on session object.
e) By calling finalize() on session object.
123. Which three of the following are true about servlet filters?
a) Cactus.jar
b) httpclient.jar
c) Httpunit.jar
d) Aspectjrt.jar
e) TaspCactus.jar
125.Which one of the following is a valid way to set up a mime mapping in the deployment
descriptor?
a) <mime-mapping-list>
<mime-type>text/plain</mime-type><extension>txt</extension>
</mime-mapping-list>
b) <mime-mapping-list>
<mime-type>text/plain</mime-type>
</mime-mapping-list>
c) <mime-mapping>
<extension>txt/plain</extension>
</mime-mapping>
d) <mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
126.Sachin wants to debug his code while executing the code he has created.
Select three methods from the following that he can use to do it.
a) System.out.println();
b) Using jdb(java debugger )tool
c) Using javadebugging class
d) Using log() method of ServletContext
e) Using debugger interface methods
a) Context attributes
b) Session attributes
c) Static variables in servlets
d) Instance variables
e) Local variables
130.Which two of the following are of the correct syntax for sendError() of HttpServletResponse
interface?
a) void sendError(int )
b) void sendError(int,int)
c) void sendError(int,String)
d) void sendError(String,String)
e) void sendError(String)
133.Which one of the following sets of tags will declare a filter and map it to a URL?
a) <filter>
<filter-name>Filter2</filter-name>
<filter-class>com.examulator.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>Filter2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
b) <filter>
<filter-name>Filter2</filter-name>
<filter-class>com.examulator.Filter</filter-class>
<filter-mapping>
<filter-name>Filter2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</filter>
c) <filter>
<name>Filter2</name>
<class>com.examulator.Filter</class>
</filter><filter-mapping>
<name>Filter2</name>
<url>/*</url>
</filter-mapping>
d) <filter>
<name>Filter2</name>
<class>com.examulator.Filter</class>
</filter>
<filter-map>
<name>Filter2</name>
<url>/*</url>
</filter-map>
135.Which one of the given options can be used in a servlet code that needs to access a binary
file kept in WEB-INF/data.zip while servicing a request?
(Assume that config refers to the ServletConfig object of the servlet and context refers to the
ServletContext object of the servlet.)
a) InputStream is = config.getInputStream("/WEB-INF/data.zip");
b) InputStream is = context.getInputStream("data.zip");
c) InputStream is = context.getResourceAsStream("/WEB-INF/data.zip");
d) InputStream is = context.getResourceAsStream("WEB-INF/data.zip");
e) InputStream is = config.getResourceAsStream("WEB-INF/data.zip");
Which one of the following statements is correct with respect to the above code?
137.Which one of the following elements of web.xml affect the whole web application instead of
a specific servlet?
a) content-type
b) init-param
c) listener
d) application
e) app-config
Which of the following if placed on the line after //comment will be valid to perform a browser
redirect?
(Select two answers)
a) ctx.sendRirect("/login.jsp");
b) response.sendRedirect("/login.jsp");
c) response.sendRedirect("login.jsp");
d) request.redirect("login.jsp");
e) request.sendRedirect("login.jsp");
139.A resource that is included using the RequestDispatcher.include method will share
attributes of the originating resource.
State true or false.
a) TRUE
b) FALSE
140. Which two of the following statements are true?