SCWCD
SCWCD
SCWCD
Sample Questions
1. A web.xml for a web application contains the following:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>sales</realm-name>
<form-login-config>
<form-login-page>/formlogin.html</form-login-page>
<form-error-page>/formerror.html</form-error-page>
</form-login-config>
</login-config>
What should formlogin.html contain?
D. Any html page that does not require the user to login
A. DIGEST
B. CLIENT-CERT
C. SECURE
D. NONE
3.You want to add third party classes bundled as a JAR file and a couple of your own
classes to a web application. Which directories would you place them in?
Select 1 correct option.
C. both in WEB-INF/classes
D. both in WEB-INF
4.Write the name of the deployment descriptor tag that allows you to write a description
for a <context-param> element. Please do not add angle brackets.
5. Which of the following statements are correct?
Select 3 correct options.
not
or not
D. Data Integrity means that the data is not modified in transit between the sender and
the receiver
E. Data Integrity means that the data cannot be viewed by anybody other than it's
intended recipient
A. FWorks/WEB-INF
B. FWorks/WEB-INF/classes
C. FWorks/WEB-INF/lib/classes
D. FWorks/classes
E. FWorks/WEB-INF/lib
A. jsp:useBean
B. jsp:useBean.property
C. jsp:useBean.getProperty
D. jsp:getProperty
E. jsp:property
Select items
A.HttpSessionListener
B.HttpSessionBindingListener
C.HttpSessionActivationListener
D.None of these
9. Given the code of doGet() method of a servlet (see exhibit). 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?
if(userId == null)
else
}
Select 3 correct options
A. req.getRequestDispatcher("errorpage.jsp").dispatch(req, res,
HttpServletResponse.SC_FORBIDDEN);
C. res.setStatus(HttpServletResponse.SC_FORBIDDEN);
E. res.sendError(HttpServletResponse.SC_FORBIDDEN);
10. Which of the following elements of web.xml affect the whole web application instead
of a specific servlet?
Select 1 correct option
A.content-type
B.init-param
C.listener
D.application
E.app-config
A.requestScope
B.application
C.header
D.page
E.pageScope
F.pageContext
13. Populate the blanks with appropriate examples given in the options.
comment
directive
declaration
scriptlet
custom tag
expression
B.<%=request.getParameter("name")%>
C.<%request.getParameter("name");%>
14. Which of the following XML fragments correctly defines a role named "manager" in
web.xml?
1.<security-role>manager</security-role>
2.<security-role rolename=manager></security-role>
3.<security>
<role-name>manager</role-name>
</security>
4.
<security-role>
<role-name>manager</role-name>
</security-role>
A.1
B.2
C.3
D.4
A.The valueBound() method is called BEFORE the object becomes accessible through
HttpSession.getAttribute()
B.The valueUnbound() method is called BEFORE the object is removed from the
HttpSession
C.The valueReplaced() method is called BEFORE the object is replaced with another
D.None of these
16. Consider the following HTML code. Which method of MyFirstServlet will be invoked
when you click on the url shown by the page?
<html>
<body>
</body>
<html>
Select 1 correct option.
A.doGet
B.doGET
C.post
D.doPost
E.doPOST
17. Your jsp page connects to the database and retrieves the data. It also formats the
data and displays it to the client. Any of these operations can throw exceptions but you
do not want to catch them all in this page and so you have written another jsp page that
is meant to handle any kind of exceptions. How would you associate that error page
named "error.jsp" with this page?
Select 2 correct options.
18. You have to send a gif image to the client as a response to a request. How will you
acquire the 'out' variable to do this?
Select 1 correct option.
19. Which of the given statements are correct regarding the following JSP page code?
<%=mystring%>
Assume that the request for this page contains a parameter mystring=hello.
20. Select the correct sequence of actions that a servlet container performs before
servicing any request.
A.Instantiate listeners defined in the deployment descriptor
ServletContextListener interface
21.Which of the following is a valid life cycle event listener interface but is NOT
configured in the web.xml?
Select 1 correct option.
A.HttpSessionListener
B.SessionActivationListener
C.HttpSessionBindingListener
D.ContextAttributeListener
E.SessionAttributeListener
22. How can you retrieve the data sent by the FORM displayed by following HTML page
code?
<html>
<body>
</form>
</body>
</html>
1)C
2)A,B
3)A
4)description or <description>
5)A,C,D
6)B
7)D
9)C,D,E
10)C
11)A,B
12)A,C,E,F
13) comment -E
directive - D
declaration -F
scriptlet -C
custom tag -A
expression - B
14)D
15)A
16)A
17)B,C
18)D
19)A
20)A,D,B,C
21)C
22)C,D
Questions - 2
1.you are using a tag library with prefix "generator", which supports a tag named
"random". This tag generates a random number and sets it to a variable named "value".
Which of the following will output this value in the page?
Select 1 correct option.
A.<generator:random>value</generator:random>
B.<generator:random><%=value%></generator:random>
C.<generator:random><% int value;%> <%=value%></generator:random>
D.<generator:random><%getParameter("value")%></generator:random>
E.None of the above
2. Which of the following pairs of HTTP method and HttpServlet class method are a
valid combination for a request and the request handler method?
Select 2 correct options.
A.GET - service()
B.POST - doPost()
C.GET - doPost()
D.GET - doGet()
E.POST - service()
3.You want to get notified whenever there is a change in the attribute list of the
ServletContext of your web application. Which listener interface would you implement?
Select 1 correct option
A.ServletListener
B.ServletContextListener
C.ServletContextAttributeListener
D.HttpServletContextListener
E.HttpServletListener
4.A JSP page myerror.jsp has been invoked as a result of an exception from another
JSP page. How can you access the Throwable object that refers to the exception in
myerror.jsp?
Select 1 correct option.
A.Using the implicit variable error
B.Using the implicit variable request.error
C.Using the implicit variable exception
D.Using the implicit variable throwable
E.None of these because the class of the implicit variable is not java.lang.Throwable
5.Which of the following are valid return values for doStartTag() method?
Select 3 correct options.
A.BodyTag.SKIP_BODY
B.Tag.SKIP
C.Tag.EVAL_BODY_INCLUDE
D.Tag.EVAL_BODY_AGAIN
E.BodyTag.EVAL_BODY_BUFFERED
6.Which of the following statements are correct for a custom tag that can take any
number of arbitrary attributes?
Select 2 correct options.
A.The body-content element for the tag in the TLD file must have a value of JSP.
B.The tag handler must implement the method setAttribute(String key, String value).
C.The tag element in the TLD file for the tag must have <dynamic-
attributes>true</dynamic-attributes>.
D.The class implementing the tag must implement
javax.servlet.jsp.tagext.DynamicAttributes interface.
E.Dynamic attributes cannot have request time expression values
F.A JSP page sets a dynamic attribute using <jsp:setDynamicAttribute> action
7.Assuming that <%@ taglib uri="/utils" prefix="util" %> occurs before the use of the
custom tags of the tag library named utils, identify the possibly valid empty custom tag
declarations. (Assume that transpose is a valid tag in the given tag library.)
Select 2 correct options.
A.<util:transpose/>
B.<util:transpose></util:transpose>
C.<util:transpose>200</util:transpose>
D.<taglib:util:transpose />
E.None of the above is correct as every tag has to have a body
8.Which of the following defines the class name of a tag in a TLD?
Select 1 correct option.
A.tag-class-name
B.tag-class
C.class-name
D.class
9.What should be the value of <body-content> subelement of element <tag> in a TLD
file if the tag should not have any contents as its body?
Select 1 correct option.
A.blank
B.empty
C.null
D.false
E.The <body-content> subelement itself should be absent
10.Which interface and method should be used to retrieve a servlet initialization
parameter value?
Select 1 correct option.
A.ServletConfig : getParameter(String name)
B.ServletConfig : getInitParameter(String name)
C.ServletContext : getInitParameter(String name))
D.ServletConfig : getInitParameters(String name)
E.ServletConfig : getInitParameterNames(String name)
11. You need to put a com.enthu.User bean referred by 'userBean' variable in request
scope with an ID of "user" from within a servlet. Which of the following statements
accomplishes this task?
Select 1 correct option.
A.request.put("user", userBean);
B.request.add(userBean, "user");
C.request.putAttribute("user", userBean);
D.request.setAttribute("user", userBean);
E.request.setParameter(userBean, "user");
F.request.put(userBean, "user");
12.Consider the following code:
{
try
catch(Exception e){ }
return super.doStartTag();
}
Which of the following options, when inserted in the above code causes the value
"hello" to be output?
Select 1 correct option.
A.JspWriter out = pageContext.getOut();
out.print("hello");
B.JspWriter out = pageContext.getWriter();
out.print("hello");
C.JspWriter out = getPageContext().getWriter();
out.print("hello");
D.JspWriter out = new JspWriter(pageContext.getWriter());
out.print("hello");
E.JspWriter out = getPageContext().getOut();
out.print("hello");
13.Which of the following is a correct JSP declaration for a variable of class
java.util.Date?
Select 1 correct option.
A.<%! Date d = new Date() %>
B.<%@ Date d = new Date() %>
C.<%! Date d = new Date(); %>
D.<%$ Date d = new Date() %>
14.Which method can be invoked on a session object so that it is never invalidated by
the servlet container automatically?
Select 1 correct option.
A.setTimeOut(-1)
B.setTimeOut(Integer.MAX_INT)
C.setTimeOut(0)
D.setMaxInactiveInterval(-1)
E.setMaxInactiveInterval(Integer.MAX_INT)
15.Which of the following elements are mandatory under the <web-app> element of a
deployment descriptor?
Select 1 correct option.
A.<doctype>
B.<app-name>
C.<servlet>
D.<doc-root>
E.None of these.
16.Which of the following implicit variables should be used by a jsp page to access a
page initialization parameter?
Select 1 correct option.
A.pageContext
B.application
C.config
D.context
E.page
17.You are given a tag library that has:
1. A tag named getMenu that takes an attribute 'subject' which can be a dynamic value.
2. A tag named getHeading that takes an attribute 'report'.
Which of the following are correct uses of this library?
Select 3 correct options.
A.<myTL:getMenu subject="Finance"/>
B.<myTL:getMenu subject="<myTL:getHeading report=1/>"/>
C.<myTL:getMenu subject='<myTL:getHeading report="1"/>'/>
D.<% String subject="HR";%> <myTL:getMenu subject="<%=subject%>"/>
E.<myTL:getHeading report="2"/>
18.You are working with a tag library which is packaged in a jar file named htmlutil.jar.
This jar file also contains a META-INF/htmlutil.tld file which has a uri element as follows:
<uri>http://www.xyzcorp.com/htmlLib</uri> What can you do to access this library from
your JSP pages
Select 1 correct option.
A.You must define the <taglib> element in the web.xml to specify
the mapping for <taglib-uri> to the location of this jar file.
B.There is no need for the <taglib> element in the web.xml, however, you need the
taglib directive in the JSP pages.
C.You can directly access the tags of this library from the JSP pages without any taglib
directive.
D.You do not need the taglib directive, but you do need to specify the <taglib> element
in the web.xml.
E.None of these.
19.Which of the following are valid iteration mechanisms in jsp?
1.
<% int i = 0;
while(i<5)
{
"Hello World"
i++;
} %>
2.
<jsp:for loop='5'>
"Hello World"
</jsp:for>
3.
<% int i = 0;
for(;i<5; i++)
{ %>
"Hello World";
<% i++;
}
%>
4.
<table>
<% Iterator it = aSet.iterator();
int i = 0;
while(it.hasNext())
{
out.println("<tr><td>"+(++i)+"</td>");
out.println("<td>"+it.next()+</td></tr>");
}
%>
</table>
5.
<jsp:scriptlet>
for(int i=0; i<5; i++)
{
</jsp:scriptlet>
<jsp:text>"Hello World!"</jsp:text>
<jsp:scriptlet>
}
</jsp:scriptlet>
Select 3 correct option.
A.1
B.2
C.3
D.4
E.5
20. Your web application wants to make use of a role named 'manager', which is
defined in the servlet container. Which of the following XML fragments must occur in the
deployment descriptor of your web application?
1.
<role name='manager' />
2.
<role>
<role-name>manager</role-name>
</role>
3.
<role>manager</role>
4.
<security-role>
<role-name>manager</role-name>
</security-role>
Select 1 correct option.
A.1
B.2
C.3
D.4
21.Consider the class shown in exhibit. Which of the following statements are correct?
1)B
2)B,D
3)C
4)C
5)A,C,E
6)C,D
7)A,B
8)B
9)B
10)B
11)D
12)A
13)C
14)D
15)E
16)C
17)A,D,E
18)B
19)C,D,E
20)D
21)A
22)B,C,E,F
23)D
24)E
25)C,D
26)E
27)C
28)D
29)C,D
30)C
Questions - 3
1. Regarding the processing of a BodyTag handler, in which of the following cases a
BodyContent object will be "pushed" into the pageContext?
Select 1 correct option.
A.If the doStartTag() returns EVAL_BODY_INCLUDE
B.If the doStartTag() returns EVAL_BODY_BUFFERED
C.If the doStartTag() returns SKIP_BODY
D.If the doStartTag() DOES NOT return SKIP_BODY
E.A BodyContent object it is always created and pushed no matter what doStartTag()
returns
2.Which of the following apply to Transfer Object design pattern?
Select 2 correct options.
A.It increases complexity by increasing the number of remote interfaces.
B. It increases network performance by introducing one coarse grained remote call for
multiple finer grained network calls
C.It reduces network traffic by introducing one coarse grained remote call for multiple
finer grained network calls
D.It increase server throughput by utilizing the CPU better
E.It increases design overhead due to versioning issues
3.Which of the following deployment descriptor snippets would you use to declare the
use of a tag library?
1.
<tag-lib>
<uri>http://abc.net/ourlib.tld</uri>
<location>/WEB-INF/ourlib.tld</location>
</tag-lib>
2.
<taglib>
<uri>http://abc.net/ourlib.tld</uri>
<location>/WEB-INF/ourlib.tld</location>
</taglib>
3.
<taglib>
<taglib-uri>http://abc.net/ourlib.tld</taglib-uri>
<taglib-location>/WEB-INF/ourlib.tld</taglib-location>
</taglib>
4.
<taglib>
<tagliburi>http://abc.net/ourlib.tld</uri>
<tagliblocation>/WEB-INF/ourlib.tld</location>
</taglib>
5.
<taglibmap>
<uri>http://abc.net/ourlib.tld</uri>
<location>/WEB-INF/ourlib.tld</location>
</taglibmap>
Select 1 correct option.
A.1
B.2
C.3
D.4
E.5
4.Which of the following design patterns is used to separate the task of writing the GUI
screens and business logic?
Select 1 correct option.
A.View Logic
B.Front Controller
C.Model View Controller
D.Business View
E.Business Delegate
5. For this jsp code to compile and run which of the given options should be true?
<jsp:useBean class="com.bookstore.Book" type="java.lang.Object" id="book" />
Select 1 correct option.
A.This statement is wrong as type attribute is invalid.
B.Book must have a public no args constructor
C.Book must have a public constructor but there is no requirement on arguments.
D.Book must have a public getInstance() method.
E.This statement will always throw an exception at runtime no matter what you do to
Book class.
6.Your servlet may throw IOException while processing a request. You want to define
an error page in your deployment descriptor so that whenever IOException is thrown,
this page is serviced to the browser. Which of the following XML fragments correctly
specify the mapping:
1.
<error-page>
<exception>java.io.IOException</exception>
<location>/html/Test.html</location>
</error-page>
2.
<error-page>
<exception-class>java.io.IOException</exception-class>
<location>/html/Test.html</location>
</error-page>
3.
<error-page>
<exception-type>java.io.IOException</exception-type>
<page-location>/html/Test.html</page-location>
</error-page>
4.
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/Enthuse/html/Test.html</location>
</error-page>
5.
<exception>
<exception-type>java.io.IOException</exception-type>
<location>/Enthuse/html/Test.html</location>
</exception>
Select 1 correct option.
A.1
B.2
C.3
D.4
E.5
7.Select the tag that comes directly under the <web-app> tag of a web.xml and that is
used to specify a class whose object will be sent notifications when changes occur to
the SevletContext?
Select 1 correct option.
A.servlet-context-listener
B.listener
C.context-listener-class
D.listener-class
E.context-listener
8.Consider the following JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that
contains this page?
<html><body>
<%
if(count != null )
out.println(count);
%>
Hello!
</body></html>
Select 1 correct option.
A.It will print Hello!
B.It will print Hello and will set the count attribute in the session.
C.It will throw a NullPointerException at request time.
D.It will not compile.
9. The following line of code exists in the doGet method of Servlet:
String sid = request.getParameter("jsessionid");
Which of the options will retrieve the HttpSession associated with the request? (Assume
that the session has already been created.)
Select 3 correct options.
(Answers)
1)C
2)B,C
3)C
4)B
5)B
6)D
7)B
8)B
9)A,D,E
Questions - 4
1.Consider the following web.xml code snippet:
<servlet>
<servlet-name>BankServlet</servlet-name>
<servlet-class>com.abc.bankapp.BankServlet</servlet-class>
<security-role-ref>
<role-name>manager</role-name>
<role-link>supervisor</role-link>
</security-role-ref>
</servlet>
Which of the following statements are correct?
Select 1 correct option.
A.The servlet code should use "manager" as a parameter in request.isUserInRole()
method.
B.The servlet code can use "manager" or "supervisor" as a parameter in
request.isUserInRole() method.
C.The servlet code should use"supervisor" as a parameter in request.isUserInRole()
method.
D.The role of "manager" must be defined in the servlet container.
E.None of these.
2.You are designing a complex webapp that uses multi tier architecture. The application
must provide interfaces for HTML as well as XML and should be maintainable.Which
design pattern would you use?
Select 1 correct option.
A.Data Access Object
B.Business Deligate
C.MVC
D.Remote Method Invocation
E.Transfer Object
3.Which of the following directives are applicable ONLY for tag files?
Select 3 correct options.
A.attribute
B.variable
C.page
D.include
E.import
F.tag
4.Which of the following are correct about FORM based authentication mechanism?
Select 3 correct options.
A.HTML FORM is used to capture the username and password of the user.
B.Password is transmitted as plain text.
C.Password is transmitted in an encrypted form.
D.Password is transmitted either in encrypted text or in plain text depending on the
browser.
E.This mechanism can be used over HTTPS.
5.Which pattern allows you to replace the presentation logic without much impact on the
data representation?
Select 1 correct option.
A.Model View Controller
B.Business Delegate
C.Transfer Object
D.Data Access Object
E.Bimodal DataAccess
6.Identify the elements that help describe the attribute characteristics of a JSP custom
tag in a TLD file.
Select 3 correct options.
A.value
B.name
C.description
D.rtexprvalue
E.class
7.Select the correct return types for ServletContext.getResource() and
ServletContext.getResourceAsStream() methods.
Select 1 correct option.
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
8.Consider the following jsp code:
,code>
<html>
<body>
</body>
</html>
What will be the output?
Select 1 correct option.
A.aaabbb
B.aaaBBB
C.AAAbbb
D.AAABBB
E.Compilation error!
9.Which of the following are valid values for the <transport-guarantee> element?
Select 3 correct options.
A.CONFIDENTIAL
B.INTEGRAL
C.SECURE
D.ENCRYPTED
E.NONE
10.Write the parent element of <session-timeout> element.
11.Consider the tag handler class shown in exhibit.
What will be printed when the above tag is used as follows in a jsp page:
try
pageContext.getOut().println("In doAfterBody()");
catch(Exception e)
return SKIP_BODY;
}
}
Select 1 correct option.
A.Hello
B.Hello World!
C.Hello In doAfterBody() World!
D.Hello In doAfterBody()
E.None of the above.
12.Which of the following HTTP protocol methods is eligible to produce unintended side
effects upon multiple identical invocations beyond those caused by single invocation?
Select 1 correct option.
A.GET
B.POST
C.HEAD
D.PUT
E.OPTIONS
13.Which method of ServletResponse would you use to set its content type?
Select 1 correct option.
A.setParameter
B.setHeader
C.setAttribute
D.setContentType
E.None of the above.
14.<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean"
/> is a valid useBean declaration.
Options.
A.True
B.False
15.Which of the following lines can be used to retrieve a servlet initialization parameter
"dbname" from the init() method of a servlet?
public void init()
}
Select 2 correct options.
A.getServletConfig().getParameter("dbname");
B.getServletConfig().getInitParameter("dbname");
C.getServletContext().getInitParameter("dbname");
D.getInitParameter("dbname");
E.getInitParameterValue("dbname");
16.Consider the following description of a tag in a TLD:
<tag>
<name>SmilyTag</name>
<tag-class>com.enthuware.ctags.SmilyTag</tag-class>
<description>
</description>
<body-content>tagdependent</body-content>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
Which of the following statements regarding the above tag are correct?
Select 2 correct options.
A.It is an empty tag.
B.It may be used as an empty tag.
C.It must have a body
D.It must implement BodyTag interface.
E.It may take an attribute named 'name'. But if present, its value must be dynamic.
17.Which of the following jsp fragments will print all the parameters and their values
present in a request?
1.
while(enum.hasMoreElements()) {
out.println(request.getParameter(obj));
} %>
2.
while(enum.hasMoreElements()) {
out.println(request.getParameter(obj));
} %>
3.
while(enum.hasMoreElements()) {
out.println(request.getParameter(obj));
} %>
4.
while(enum.hasMoreElements()) {
<%=request.getParameter(obj); %>
<% } %>
5.
while(enum.hasMoreElements()) {
<%=request.getParameter(obj)%>
<% } %>
Select 2 correct options.
A.1
B.2
C.3
D.4
E.5
18.Which of the following statements are valid JSP directive?
Select 2 correct options.
A.<%! int k = 10 %>
B.<% int k = 10; %>
C.<%=somevariable%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%@ page language="java" import="com.abc.*"%>
19.How can you ensure the continuity of the session while using
HttpServletResponse.sendRedirect() method when cookies are not supported by the
client?
Select 1 correct option.
A.By using hidden parameters.
B.By enconding the redirect path with HttpServletResponse.encodeRedirectURL()
method.
C.By using HttpSession.encodeURL() method.
D.By using HttpServletRequest.encodeURL() method.
E.By using HttpServletResponse.encodeURL() method.
20.Which of the following are valid implicit variables in a JSP page?
Select 2 correct options.
A.error
B.page
C.this
D.root
E.context
21.A Tag Handler implements BodyTag interface. How many times its doAfterBody
method may be called?
Select 1 correct option.
A.BodyTag does not support doAfterBody.
B.0
C.1
D.0 or 1
E.Any number of times.
22.Given: You have configured a listener class (see exhibit) in web.xml of a web
application. Now, consider the following code for the doGet() method of a servlet for the
same web application.
,code>
public void doGet(HttpServletRequest req, HttpServletResponse res)
System.out.println(this.getServletContext().getAttribute("key"); //2
}
Which option can be inserted at //1 in the listener code so that servlet code at //2 prints
100?
import javax.servlet.*;
{
Integer key = new Integer(100);
}
Select 1 correct option.
A.this.setAttribute("key", key);
B.this.getServletContext().setAttribute("key", key);
C.this.getContext().setAttribute("key", key);
D.sce.getContext().setAttribute("key", key);
E.sce.getServletContext().setAttribute("key", key);
23.Which of the following interfaces declares the methods jspInit() and jspDestroy()?
Select 1 correct option.
A.javax.servlet.jsp.JSP
B.javax.servlet.jsp.JspServlet
C.javax.servlet.jsp.JspPage
D.javax.servlet.jsp.HttpJspPage
E.javax.servlet.jsp.HttpJspServlet
24.Which of the following statements are correct JSP directives?
Select 2 correct options.
A.<%@ page %>
B.<%! taglib uri="http://www.abc.com/tags/util" prefix="util" %>
C.<% include file="/copyright.html"%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%$ page language="java" import="com.abc.*"%>
25.Which of the following classes hides the implementation details and provides a
standard API to the services provided by the servlet container to a jsp page?
Select 1 correct option.
A.HttpSession
B.Servlet
C.JspPage
D.ServletContext
E.PageContext
26.Which of the following are true regarding the parameters defined using the <context-
param> element of a deployment descriptor?
Select 2 correct options.
A.They are thread safe.
B.They are accessible from multiple threads simultaneously and from any servlet of the
web application.
C.They can be modified using the setAttribute() method.
D.They can be modified using the setParameter() method.
E.They can be modified using the setInitParameter() method.
27.How can you explicitly expunge the session object?
Select 1 correct option.
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.
28.You have declared a useBean tag as:
<jsp:useBean id="man" class="animal.Human" scope="application"/>
In which type of object will this bean be kept?
Select 1 correct option.
A.Servlet
B.HttpSession
C.ServletContext
D.ServletConfig
E.ApplicationContext
29.Which of the following is a sensible way of sending an error page to the client in case
of a business exception that extends from java.lang.Exception?
Select 2 correct options.
A.Catch the exception and use RequestDispatcher to forward the request to the error
page.
B.Don't 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.Don't do anything, the servlet container will automatically send a default error page
30.Business delegate pattern should be used to enable communication between the
JSP code and the enterprise javabeans.
Options.
A.True
B.False
(Answers)
1)A
2)C
3)A,B,F
4)A,B,E
5)A
6)B,C,D
7)C
8)A
9)A,B,E
10)session-config
11)A
12)B
13)D
14)B
15)B,D
16)B,D
17)C,E
18)D,E
19)B
20)B,C
21)E
22)E
23)C
24)A,D
25)E
26)A,B
27)B
28)C
29)A,C
30)A
Questions - 5
1.Assume that the following header is present in a request sent to a servlet:
Accept: image/gif, image/jpeg, image/bmp
What will be returned when the servlet code calls request.getHeader("Accept")?
Select 1 correct option.
A.A Header object containing, name as "Accept" and value as "image/gif".
B.A Header object containing, name as "Accept" and value as "image/gif, image/jpeg,
image/bmp".
C.A String array containing "image/gif""
D.A String containing "image/gif, image/jpeg, image/bmp".
E.A String array containing "image/gif", "image/jpeg", image/bmp"
2. You need to send large amount of binary data from the browser to a servlet to be
processed. (Say, you want to attach a file while sending email through a web based
system). What HTTP method would you use?
Select 1 correct option.
A.GET
B.POST
C.HEAD
D.HIDDEN
E.PUT
3.Which of the following is a possible way to configure an HttpSessionAttributeListener?
Select 1 correct option.
A.By calling HttpSession.addAttributeListener(...)
B.By calling HttpSession.addHttpSessionAttributeListener(...)
C.An object of a class implementing this interface is automatically configured when it is
added to the session.
D.None of these.
4.Servlet Container calls the init method on a servlet instance ...
Select 1 correct option.
A.For each request to the servlet
B.For each request to the servlet that causes a new session to be created.
C.For each request to the servlet that causes a new thread to be created.
D.Only once in the life time of the servlet instance
E.If the request is from the user whose session has expired.
F.Initialy when the servlet instance is create and then at request time if the request is
from the user whose session has expired.
5.Which of the following methods may be called on a custom tag handler that
implements IterationTag interface?
Select 2 correct options.
A.doStartTag
B.doBodyTag
C.doAfterBody
D.doInitBody
E.doEvalBody
6.Which of the following elements of web.xml defines a mapping between a servlet and
a URL pattern?
Select 1 correct option.
A.mapping
B.servlet-url
C.url_mapping
D.url_pattern
E.servlet-mapping
7.Following is the code for doGet() method of TestServlet. Which of the given
statements about it are correct?
try
RequestDispatcher rd =
this.getServletContext().getRequestDispatcher("Login.jsp"); // 1
rd.forward(req, res); // 2
catch(Exception e)
e.printStackTrace();
}
}
Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with: RequestDispatcher rd =
req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with: RequestDispatcher rd =
req.getRequestDispatcher("Login.jsp");
8.Consider the web.xml snippet shown in the exhibit.
Now consider the code for a jsp file named unprotected.jsp:
<html>
<body>
</body>
</html>
Which of the following statements hold true when unprotected.jsp is requested by an
unauthorized user?
<web-app>
...
<security-constraint>
<web-resource-collection>
<web-resource-name>test</web-resource-name>
<url-pattern>/jsp/protected.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>manager</role-name>
</auth-constraint>
</security-constraint>
...
</web-app>
Select 1 correct option.
A.The user will be prompted to enter user name and password
B.An exception will be thrown
C.protected.jsp will be executed but it's output will not be included in the response
D.The call to include will be ignored
E.None of these
9.Which of the following JSP elements can have a <jsp:param ...> element in its body?
Select 1 correct option.
A.<jsp:include ...>
B.<%@ include ...>
C.<jsp:directive.include .../>
D.<%@ forward ...>
E.<jsp:action ...>
10.Which of the following implicit variables should be used by a jsp page to access a
resource and to forward a request to another jsp page?
Select 1 correct option.
A.pageContext and config
B.application and config
C.config and pageContext
D.application for both
E.config for both
11.In which of the following situations will a session be definitely invalidated?
Select 3 correct options.
A.The container is shutdown and brought up again
B.No request comes from the client for more than "session timeout" period.
C.A servlet explicitly calls invalidate() on a session object.
D.A servlet explicitly calls invalidate() on a session object.
12.Your jsp page uses classes from java.util package. Which of the following statement
would allow you to import the package?
Select 1 correct option
A.<%@import java.util.* %>
B.<%import="java.util.*"@%>
C.<%@ page import="java.util.*"%>
D.<%@ page java="java.util.*"@%>
E.<%@ page import="java.util.*"@%>
13.Consider the following contents for two JSP files:
In file companyhome.jsp:
<html><body>
</body></html>
In file companynews.jsp:
<h3>Todays News</h3>
<html>
<body>
<form action="/myapp/RegisterServlet">
</form>
</body>
</html>
Select 1 correct option.
A.servicePost(HttpRequest, HttpResponse);
B.doPOST(HttpRequest, HttpResponse);
C.post(HttpRequest, HttpResponse);
D.doPost(HttpRequest, HttpResponse);
E.None of the above.
15.You are building the server side of an application and you are finalizing the
interfaces that you will provide to the client side. But you have not yet decided whether
the business rules will be fully implemented as stored procedures or in the java code.
Which design pattern you should use to mitigate this concern?
Select 1 correct option.
A.Model View Controller
B.Data Access Object
C.Business Delegate
D.Facade
E.Transfer Object
16.Which of the following XML frgaments correctly define the <login-config> element of
web.xml?
(See Exhibit.)
1.
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>test</realm-name>
</login-config>
2.
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>test</realm-name>
<form-login-config>
<form-login-page>/jsp/login.jsp</form-login-page>
<form-error-page>/jsp/error.jsp</form-error-page>
</form-login-config>
</login-config>
3.
<login-config>
<auth-method>FORM</auth-method>
<realm-name>test</realm-name>
<form-login-config>
<form-login-page>/jsp/login.jsp</form-login-page>
<form-error-page>/jsp/error.jsp</form-error-page>
</form-login-config>
</login-config>
4.
<login-config>
<auth-method>FORM</auth-method>
<realm-name>test</realm-name>
</login-config>
5.
<login-config>
<auth-method>SECURE</auth-method>
<realm-name>test</realm-name>
</login-config>
Select 3 correct options.
A.1
B.2
C.3
D.4
E.5
17.What are the following deployment descriptor elements used for?
<login-config> <security-constraint> <security-role> Select 1 correct option.
A.Authorization
B.Authentication
C.Privacy
D.Authentication and Authorization
E.Data integrity.
18.You want to do some calculations within the object whenever it is added to the
session. What would you do to accomplish this?
Select 1 correct option
A.Make the class of the object implement HttpSessionBindingListener
B.Configure a HttpSessionAttributeListener in deployment descriptor
C.Make the class of the object implement HttpSessionListener
D.Configure a HttpSessionActivationListener in deployment descriptor
E.Only way is to configure a HttpSessionAttributeListener in the deployment descriptor
19.GET method is not suitable for which of the following operations?
Select 2 correct option.
A.Retrieving an image
B.Retrieving a zip file
C.Submitting a form not containing login or other critcal information
D.Submitting a login form
E.Updating a database
20.In the case of JSP pages, what is the type of the implicit variable 'out'?
Select 1 correct option.
A.OutputStream
B.PrintStream
C.PrintWriter
D.JspWriter
E.DataOutputStream
21. Match the following.
Comment
directive
declaration
scriptlet
Custom tag
expression
<tags:simple name='bob' />
<%=request.getParameter("name")%>
<%request.getParameter("name");%>
<jsp:directive.include file='hello.jsp' />
<%-- String x = "123" --%>
<%!String x = "123"; %>
22.Consider the following tag occuring in a JSP page:
<%@page import="java.util.*"%> Which of the following is the XML equivalent of the
above tag?
Select 1 correct option.
A.<directive.page import="java.util.*"/>
B.<page import="java.util.*"/>
C.<%jsp:directive.page import="java.util.*"%>
D.<jsp:page import="java.util.*"/>
E.<jsp:directive.page import="java.util.*"/>
23.Your servlet may throw IOException while processing a request. You want to define
an error page in your deployment descriptor so that whenever IOException is thrown,
this page is serviced to the browser. Which of the following XML fragments correctly
specify the mapping:
1.
<error-page>
<exception>java.io.IOException</exception>
<location>/html/Test.html</location>
</error-page>
2.
<error-page>
<exception-class>java.io.IOException</exception-class>
<location>/html/Test.html</location>
</error-page>
3.
<error-page>
<exception-type>java.io.IOException</exception-type>
<page-location>/html/Test.html</page-location>
</error-page>
4.
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/Enthuse/html/Test.html</location>
</error-page>
5.
<exception>
<exception-type>java.io.IOException</exception-type>
<location>/Enthuse/html/Test.html</location>
</exception>
A.1
B.2
C.3
D.4
E.5
24.How can you ensure the continuity of the session while using
HttpServletResponse.sendRedirect() method when cookies are not supported by the
client?
Select 1 correct option
A.By using hidden parameters.
B.By enconding the redirect path with HttpServletResponse.encodeRedirectURL()
method.
C.By using HttpSession.encodeURL() method.
D.By using HttpServletRequest.encodeURL() method.
E.By using HttpServletResponse.encodeURL() method
25.Which of the following XML fragments correctly defines a role named "manager" in
web.xml?
1.
<security-role>manager</security-role>
2.
<security-role rolename=manager></security-role>
3.
<security>
<role-name>manager</role-name>
</security>
4.
<security-role>
<role-name>manager</role-name>
</security-role>
Select 1 correct option.
A.1
B.2
C.3
D.4
26.Which of the following methods of HttpServletRequest can be used to retrieve the
parameter values sent from the browser?
Select 2 correct options
A.getParameter(String name);
B.getParameter(String name, String defaultValue);
C.getParameterNames();
D.getParameterValues(String name);
E.getParameters(String name);
27.Consider the code for the web.xml for a web application (See exhibit).
Assume that a request: http://localhost:8080/test/aaa/abc.a is sent to this web
application named test.
Which of the following statements are correct?
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN"
"http://java.sun.com/dtd/web-app_2_4.dtd">
<web-app>
<servlet>
<servlet-name>TestServlet</servlet-name>
<jsp-file>/requestinfo.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>*.a</url-pattern>
</servlet-mapping>
</web-app>
Select 1 correct option.
A.Path Info of the request will be /aaa/abc.a
B.RequestPath of this request will be /test//aaa/abc.a
C.ContextPath of this request will be /test/aaa
D.This request will be serviced by requestinfo.jsp
E.None of these.
28.You are using a tag library with prefix "sequenceengine" which supports a tag named
"fib". This tag expects a parameter named "limit" of type int. Which of the following is a
correct use of this tag?
Select 1 correct option.
A.<sequenceengine:fib>20</sequenceengine:fib>
B.<fib:sequenceengine>20</fib:sequenceengine>
C.<sequenceengine:fib attribute-name="limit" attribute-
value="20"></sequenceengine:fib>
D.<sequenceengine:fib limit="20"></sequenceengine:fib>
E.<fib:sequenceengine limit="20"></fib:sequenceengine>
29.How can you redirect the request from a servlet to another resource if the servlet
encounters an exception?
Select 2 correct options
A.This cannot be done unless the exception is caught in the servlet.
B.By specifying a mapping between exception class and the resource in web.xml
C.This can be done only if the exception is a subclass of javax.servlet.ServletException
D.This can be done even if the exact class of the exception is not known at compile time
30.Which of the given options correctly declare a useBean tag?
Select 3 correct options
(Answers)
1)D
2)B
3)D
4)D
5)A,C
6)E
7)C,E
8)E
9)A
10)D
11)B,C,D
12)C
13)B
14)E
15)C
16)A,B,C
17)D
18)A
19)D,E
20)D
21)comment <%-- String x = "123" --%>
directive <jsp:directive.include file='hello.jsp' />
declaration <%!String x = "123"; %>
scriptlet <%request.getParameter("name");%>
custom tag <tags:simple name='bob' />
expression <%=request.getParameter("name")%>
22)E
23)D
24)B
25)D
26)A,D
27)D
28)D
29)B,D
30)A,B,E
Questions - 6
1.Which constant is used to notify the container to reevaluate the custom tag's body?
Please select one correct answer.
A. EVAL_BODY
B. EVAL_BODY_TAG
C. EVAL_BODY_AGAIN
D. EVAL_BODY_INCLUDE
2. Which of the following statements regarding the JSP action tag are TRUE?
Please select three correct answers.
A. Provides translation-time instructions to the JSP engine.
B. Can be used to declare a JavaBean instance in a JSP page
C. Can be used to generate HTML code to embed an applet on a web page
D. User-defined actions can be created
E. language is a standard JSP action.
3.Which of the following methods can be used to pass request to another servlet to
handle by using the RequestDispatcher?
Please select two correct answers.
A. request(ServletRequest req, ServletResponse res)
B. include(ServletRequest req, ServletResponse res)
C. dispatch(ServletRequest req, ServletResponse res)
D. forward(ServletRequest req, ServletResponse res)
E. process(ServletRequest req, ServletResponse res)
4. Given the following code snippet, what would be the output you can expect to see on
the web page?
Please select one correct answer.
import javax.servlet.*;
import javax.servlet.http.*;
int MAX_AGE;
Cookie cookie = new Cookie("user", user);
cookie.setMaxAge(MAX_AGE);
response.addCookie(cookie);
A. If MAX_AGE = 10 the cookie will expire after 10 seconds.
B. If MAX_AGE = 10 the cookie will expire after 600 seconds.
C. If MAX_AGE = 0 the cookie will be deleted.
D. If MAX_AGE = -1 the cookie is not stored persistently
E. If MAX_AGE = -1; the code will generate run-time error.
12. In which directory you will most likely find the file myBaseUtil.jar?
Please select two correct answers.
A. example/WEB-INF
B. example/lib
C. example/WEB-INF/lib
D. example/WEB-INF/classes
E. example/META-INF/lib
13.Which of the following requirements are needed for FORM based authentication in a
web based application?
Please select four correct answers.
A. The session attribuite j_sessionid must be set.
B. The action or url must be j_security_check.
C. The name attribute for the username must be j_username
D. The form method must be POST.
E. The name attribute for the password must be j_password.
F. Client side cookie must be enabled.
14.Which of the following deployment descriptor snippet will map the following request
URI: /tech/hello/index.jsp for web application with context path as "tech"?
Please select one correct answer.
A. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
B. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*.jsp</url-pattern>
</servlet-mapping>
C. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/index.jsp</url-pattern>
</servlet-mapping>
D. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>hello/*</url-pattern>
</servlet-mapping>
15. Which of the following methods will enable you to get one or more values from a
request object?
Please select two correct answers.
A. getParameter(String name)
B. getParameters(String name)
C. getAllParameters()
D. getParameterValues(String name)
E. getAllAttributes()
16. Is the following statement TRUE or FALSE?
Please select one correct answer.
The four methods for session management in the context of web-based application are:
Cookie, HttpSession object, URL rewriting and Hidden value.
A.True
B.False
17. Which of the following packages are implicitly imported in the JSP page?
Please select three correct answers.
A. java.lang.*
B. java.util.*
C. javax.servlet.*
D. javax.servlet.jsp.*
E. javax.servlet.jsp.tagext.*
18.Which of the following is NOT an authentication method used by a web container?
Please select one correct answer.
A. BASIC
B. DIGEST
C. SSL
D. FORM
19. Which methods can be used for writing logging message to servlet log file?
Please select two correct answers.
A. log(String msg)
B. log(int code, String msg)
C. log(String msg, Throwable t)
D. log(int code, String msg, Throwable t)
20.Which tag is used in web.xml to mark a web application to be suitable for running
between multiple systems.
Please select one correct answer.
A. multiple
B. distributable
C. resource-ref
D. transferrable
E. splitable
21. Which of the following are VALID servlet error attributes?
Please select three correct answers.
A. javax.servet.error.status_code
B. javax.servet.error.exception
C. javax.servet.error.uri
D. javax.servet.error.message
E. javax.servet.error.query
22. Which statement is TRUE about the following jsp code snippet?
Please select one correct answer.
<%
String theKey = "key";
String theValue = "value";
session.removeAttribute(theKey); //1
%>
A.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
</tag>
...
</taglib>
B.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<body-content>SERVLET</body-content>
</tag>
...
</taglib>
C.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<attribute>
<name>name</name>
</attribute>
</tag>
...
</taglib>
D.
taglib>
...
<tag>
<name>myTag</name>
<tei-class>MyTagInfo</tei-class>
<body-content>JSP</body-content>
</tag>
...
</taglib>
E.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<tei-class>MyTagInfo</tei-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
...
</taglib>
24.Which of the following statement is FALSE regarding JSP page directive attributes
default value?
Please select one correct answer..
A. The session attribute has default value as true
B. The buffer attribute has default value as 8kb
C. The autoflush attribute has default value as false
D. The isThreadSafe attribute has default value as true
E. The isErrorPage attribute has default value as false
F. The pageEncoding attribute has default value as ISO-8859-1
25.Which of the following deployment descriptor tags are used for context level
parameter initialization?
Please select three correct answers.
A. param-name
B. context-name
C. context-param
D. param-value
E. context-value
F. context-attrib
26. Given the following code snippet, what would be the output you can expect to see
on the web page?
Please select one correct answer.
// Calling servlet:
// Target servlet:
res.setContentType("text/html");
java.io.PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>This is my servlet!</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
out.close();
}
A.
index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
B.
/index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class
C.
/index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/classes/basic.jar
/WEB-INF/classes/Test.class
D.
/index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class
E.
/index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
F.
index.html
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jsp/login.jsp
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
33. Which of the following data element will definitely be thread-safe?
Please select one correct answer
A. Local variables
B. Instance variables
C. Static variables
D. Class variables
E. Context attributes
34. Select the correct order that JSP methods are invoked by servlet container
Please select one correct answer.
A. jspInit(), jspService(), jspDestroy()
B. jspInit(), _jspService(), jspDestroy()
C. _jspInit(), jspService(), _jspDestroy()
D. _jspInit(), _jspService(), _jspDestroy()
35. Which of the following element is not included in a URL?
Please select one correct answer
A. Client ip
B.Protocol
C.Server Name
D.Query string
E.Port name
36. Which of the following listeners is notified when a session is initialized?
Please select one correct answer.
A. HttpSessionBindingListener
B. SessionBindingListener
C. HttpSessionListener
D. HttpSessionListener
E. HttpSessionChangedListener
37. Which of the following best describes the life cycle of a JSP?
Please select one correct answer.
A.
JSP page is translated into a servlet code
Servlet code is compiled
Servlet is loaded into memory
Servlet instance is created
B.
JSP page is translated into a servlet code
Servlet is loaded into memory
Servlet code is compiled
Servlet instance is created
C.
JSP is compiled
JSP is translated into a servlet code
Servlet is loaded into memory
Servlet instance is created
D.
JSP is loaded into memory
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory
E.
JSP page is translated into a servlet code
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory
38. Please identify the three methods declared in javax.servlet.Filter
Please select three correct answers.
A.service
B.init
C.destroy
D.filter
E.doFilter
39.Which of the following deployment descriptor segments are VALID for security-
related configuration of a web application?
Please select two correct answers.
A.
<login-config>
<auth-method>FORM</auth-method>
<login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</login-config>
</login-config>
B.
<security-role>
<description>My description.</description>
<role-name>Manager</role-name>
</security-role>
C.
<security-constraint>
<web-resource-collection>
<web-resource-name>SecureStuff</web-resource-name>
<url-mapping>/servlet/secure</url-mapping>
<http-method>POST</http-method>
</web-resource-collection>
</security-constraint>
D.
<security-constraint>
<auth-constraint>
<role-name>Broker</role-name>
</auth-constraint>
</security-constraint>
E.
<security-constraint>
<web-resource-collection>
<web-resource-name>SecureStuff</web-resource-name>
</web-resource-collection>
<auth-constraint>
<role-name>Broker</role-name>
</auth-constraint>
</security-constraint>
40.Based on the following information, please construct the full path for the servlet.
Please select one correct answer
docbase = c:/temp/
context path = /test
alias name = MyMail
servlet-name = com.jiris.common.util.MailServlet
url-pattern = /mail/*
A.c:/temp/mail/com/jiris/common/util/MailServlet.class
B.c:/temp/test/com/jiris/common/util/MailServlet.class
C.c:/temp/mail/test/com/jiris/common/util/MailServlet.class
D.c:/temp/test/mail/com/jiris/common/util/MailServlet.class
41.The ServletContext object are accessible from which of the following objects?
Please select three correct answers.
A.HttpServlet
B.GenericServlet
C.HttpSession
D.ServletConfig
E.ServletResponse
42.Which of the following method is used to store object into a request object?
Please select one correct answer
A. addAttribute(String name, String obj)
B. putAttribute(String name, Object obj)
C. setAttribute(String name, String obj)
D. setAttribute(String name, Object obj)
E. addObject(String name, Object obj)
43. Which request method will be invoked for the following code?
Please select one correct answer.
,code>
<html>
<body>
<form action=´/servlet/comment´>
<p>Please provide your comment here:</p>
<input type=´text´ size=´40´ name=´Comment´>
<input type=´submit´ value=´Submit´>
</form>
</body>
<html>
A.GET
B.POST
C.HEAD
D.TRACE
E.PUT
44.Which of the following method might be invoked more than one time?
Please select one correct answer
A.doStartTag()
B.doInitBody()
C.doAfterBody()
D.doEndTag()
45.Which of the following methods are used to send an error page to the client?
Please select two correct answers
A.log(String msg)
B.log(String msg, Throwable t)
C.sendError(int code)
D.sendError(int code, String msg)
E.sendError(int code, String msg, Throwable t)
46.Which of the following requests should be performed by using a POST method?
Please select two corretion.
A.Inserting a record into a database
B.Accessing a static page
C.Retrieving an image
D.Sending credit card number
E.Searching record in a database
47.Which of the following are CORRECT ways to define inactive period of 5 minutes of
a session before the server invalidates it?
Please select two correct answers
A.<session-timeout>5</session-timeout>
B.<session-timeout>300</session-timeout>
C.session.setMaxInactiveInterval(5);
D.session.setMaxInactiveInterval(300);
E.session.invalidate(5);
48.Which are the two mandatory attributes for JSP taglib directive?
Please select two correct answers.
A.uri
B.id
C.name
D.prefix
E.value
F.location
49.A session can be invalidated by which of the following:
Please select three correct answers
A.After a default period of inactivity, say 30 minutes
B.Client side user closes the browser
C.After a specified period of inactivity, say 10 minutes
D.Client side user machine crashes
E.Explicitly invalidate a session through method calls
50.What is the method declaration for the method used in the HttpServlet class that
handles the HTTP GET request?
Please select one correct answer
A.doGet(ServletRequest req, ServletResponse res)
B.getPage(ServletRequest req, ServletResponse res)
C.doGet(HttpServletRequest req, HttpServletResponse res)
D.service(HttpServletRequest req, HttpServletResponse res)
(Answers)
1)C
To notify the container to reevaluate the custom tag's body, you must return a value of
IterationTag.EVAL_BODY_AGAIN in the doAfterBody() method.
2)B,C,D
jsp:bean declares the use of a JavaBean instance in a JSP page.
jsp:plugin instructs the JSP engine to generate appropriate HTML code for embedding
applets on a web page.
Custom tags (taglibs) allow user-defined actions to be created.
Answer A is incorrect because the action JSP tag provides request-time instructions to
the JSP engine.
Standard action types : jsp:include, jsp:forward, jsp:useBean, jsp:setProperty,
jsp:getProperty, jsp:plugin
3)B,D
You can use either forward(...) or include(...) method to pass the request to another
servlet to handle. While for forward(...), the control is passing to target servlet, for
include(...), the control is still with the current servlet.
4)C,E
You need to override the service() method when you extends GenericServlet.
You need to call super.init(config) if you override this method.
5)B
A Data Access Object pattern is used to encapsulate database access functions. By
putting database-specific SQL code into a separate layer as DAO layer, it is easy to
modify it without affecting business logic layer, thus increase code manageability.
6)A,B
7)C,E
8)D
9)Client-Cert
The correct answer is CLIENT-CERT which stands for client certificate. It requires the
client to provide a digital certificate containing information about the issuer, signature,
serial number, key type, etc
10)B
11)A,C,D
12)C
13)B,C,D,E
14)C
15)A,D
16)A
17)A,C,D
18)C
19)A,C
20)B
21)A,B,D
22)C
23)A,C,E
24)C
25)A,C,D
26)C
27)D
28)E
29)A,B,C
30)A,D,E
31)B
32)A,F
33)A
34)B
35)A
36)C
37)A
38)B,C,E
39)B,E
40)B
41)A,C,D
42)D
43)A
44)C
45)C,D
46)A,D
47)A,D
48)A,D
49)A,C,E
50)C
Questions - 7
1. Consider the following code:
<html><body>
</body></htm>
<h3>Todays News</h3>
Select 1 correct option.
A.When companyhome.jsp is requested, the output will contain "welcome..." as well as
"Todays News".
B.companyhome.jsp will not compile
C.companynews.jsp will not compile
D.Both the files will compile but will throw an exception at runtime
E.None of these
4.Which HTTP method is used in FORM based Authentication?
Select 1 correct option.
A.POST
B.GET
C.FORM
D.HEAD
5.Consider the following code snippets. What will be displayed on the browser when a
GET request is sent to FirstServlet assuming that the buffer is large enough to hold all
the data before sending the data to the client?
out.println("<html><body>Page 1");
RequestDispatcher rd = response.getRequestDispatcher("SecondServlet");
rd.forward(request, response);
out.println("<br>Page 2</body></html>");
<html><body>
<form action="/myapp/servlet/EmailCatcherServlet">
<input type="submit">
</form>
</body></html>
Select 2 correct options.
A.getParameter("email") of ServletRequest
B.getParameterValues("email") of ServletRequest
C.getField("email") of HttpServletRequest
D.getFormValue("email") of HttpServletRequest
E.getParameters("email") of HttpServlet
10.What will the following JSP page print?
<% { %>
sb.append("Hello");
<% } %>
<%=sb%>
Select 1 correct option.
A. It will print null
B.It will print "Hello"
C.It will not compile because <jsp:useBean> cannot be used inside a block
D.It will not compile because StringBuffer is not a bean
E.None of these
11.Which HTTP method would you use to test the validity, accesibility, or modification
time of a hyperlink?
Select 1 correct option.
A.GET
B.POST
C.HEAD
D.OPTIONS
E.PUT
12.A function has been defined in a tag library descriptor as follows:
<taglib>
...
<function>
<name>transform</name>
<function-class>com.enthu.Functions</function-class>
<function-signature>java.lang.String transformString(String)</function-signature>
</function>
...
</taglib>
Which of the following statements are correct?
Select 1 correct option.
A.The Function class must have a method with the signature: public String
transform(String arg);
B.The Function class must have a function with the signature: public String
transformString(String arg);
C.The Function class may have any method of the type: public static XXX(String s); but
the method name (ie. XXX) must be mapped to "transform" in web.xml.
D.The Function class may have any method of the type: public static XXX(String s); but
the method name (ie. XXX) must be mapped to "transformString" in web.xml.
E.None of these
13.In your report.jsp page, you want to include the output of "customer.jsp" page. But
this page requires an additional parameter "custid", which is not present in the request.
Which of the following code snippents does this.
1.
<jsp:include page="customer.jsp" custid="1234"/>
2.
<jsp:include page="customer.jsp">
<jsp:param>
<name>custid</name>
<value>1234</value>
</jsp:param>
</jsp:include>
3.
4.
<jsp:include page="customer.jsp">
</jsp:include>
Select 1 correct option.
A.1
B.2
C.3
D.4
14.Which of the following statements are correct regarding the import tag of JSTL?
Select 2 correct options.
A.The String value of the imported content can be made available for use outside of the
tag in 'var' variable.
B.If the url contains a relative path, then the resource must exist in the same webapp.
C.import tag is more efficient than jsp:include action in the case when large amount of
data is imported only to be given to another tag.
D.import tag is useful to convert URL when cookies are not supported by the client.
E.The content imported by the import tag can be made available only through a String
object.
15.What are the implications of using the HTTP GET method for a form submission?
Select 3 correct options.
A.You cannot pass binary data to the server
B.You cannot send unlimited (or a lot of) data to the server
C.You cannot send multiple values for one parameter to the server
D.You can only reply with the HEADER information in the response.
E.The parameters will be appended to the URL as a query string
16.It important to note that response of a POST request are never cached.
1.
<taglib>
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
2.
<taglib>
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.jar</taglib-location>
</taglib>
3.
<taglib id="ABC_MATH_LIB">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
4.
<taglib name="ABC_MATH_LIB">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.jar</taglib-location>
</taglib>
5.
<taglib author="ABCINC">
<taglib-uri>/binomial</taglib-uri>
<taglib-location>/WEB-INF/MathLib.tld</taglib-location>
</taglib>
Select 3 correct options.
A.1
B.2
C.3
D.4
E.5
17.Consider the jsp code:
<html>
<head>
</head>
<body>
</body>
</html>
In which method of the generated servlet will the declaration for 'k' be placed?
Select 1 correct option
A.This will not compile as you cannot put jsp code in the <head> element
B.init()
C.doGet()
D._jspService()
E.constructor of the servlet.
18.Which event is received by a registered listener when an attribute is added to
HttpSession?
Select 1 correct option
A.HttpSessionChangeEvent
B.HttpSessionEvent
C.HttpAttributeChangeEvent
D.HttpSessionBindingEvent
E.HttpAttributeEvent
19.You are using a tag library with prefix "generator", which supports a tag named
"random". This tag generates a random number and sets it to a variable named "value".
Which of the following will output this value in the page?
Select 1 correct option
A.<generator:random>value</generator:random>
B.<generator:random><%=value%></generator:random>
C.<generator:random><% int value;%> <%=value%></generator:random>
D.<generator:random><%getParameter("value")%></generator:random>
E.None of the above.
20.Identify the techniques that can be used to implement 'sessions' if the client browser
does not support cookies.
Select 3 correct options
A.Using Http headers
B.Using https protocol.
C.Hidden form fields
D.URL rewriting
E.It cannot be done without cookie support.
21.Which of the following are valid JSP scriptlets?
Select 2 correct options.
A.<% String uid = LoginHelper.login(request) %>
B.<% String uid = LoginHelper.login(request); %>
C.<%! String uid = LoginHelper.login(request) %>
D.<%@ String uid = LoginHelper.login(request) %>
E.<% for(int i=0; i< 10; i++) { out.println(i); } %>
22.Consider the following web.xml code snippet:
<servlet>
<servlet-name>BankServlet</servlet-name>
<servlet-class>com.abc.bankapp.BankServlet</servlet-class>
<security-role-ref>
<role-name>manager</role-name>
<role-link>supervisor</role-link>
</security-role-ref>
</servlet>
}
Select 2 correct options.
A.getServletConfig().getParameter("dbname");
B.getServletConfig().getInitParameter("dbname");
C.getServletContext().getInitParameter("dbname");
D.getInitParameter("dbname"); E.getInitParameterValue("dbname");
(Answers)
1)D
2)A,D
3)A
4)A
5)B
6)A,C
7)D
8)B,C
9)A,B
10)E
11)C
12)E
The Function class must have a method with signature: public static String
transformString(String arg);
A is incorrect. The method name must be the same as given in <function-signature>
element.
B is incorrect. Method name is correct but it should also be static.
13)D
14)A,C
15)A,B,E
16)A,B,C
17)D
This is a scriptlet and they always go inside the service method. ie. they are local to the
request. A is incorrect. You can put JSP code anywhere
18) D
Following is the mapping of Listeners and their corresponding events.
HttpSessionListener : HttpSessionEvent
HttpSessionAttributeListener : HttpSessionBindingEvent
HttpSessionBindingListener : HttpSessionBindingEvent
Observe that both - HttpSessionAttributeListener and HttpSessionBindingListener, use
HttpSessionBindingEvent.
19) B
C is incorrect It'll give an exception saying value is not initialized!
20) B,C,D
B is correct Unlike HTTP, HTTPS uses SSL which is a stateful protocol.
C is correct Remember that this is a non-standard and obsolete way.
This can only be done in an application specific way and requires that the page has a
form.
21)B,E
A is incorrect. It does not have an ending semicolon
C is incorrect. ! is used for declarations
D is incorrect. @ is used for directives
22)A
D is incorrect "supervisor" must be defined in the container. For example, in
conf/tomcat-users.xml for Tomcat.
<security-role-ref> is used to map the role names hard coded in the servlet code to the
actual role names defined in the servlet container.
22)C
The statement "...should provide XML and HTML interfaces..." means the same data is
represented in different ways, therefore this is MVC.
23) A,B,F
B Valid only for tag files.
D is incorret include directive is valid for regular JSP file also
E is incorrect No such directive
24)A,B,E
C is incorrect This is done in HTTP Digest authentication mechanism
25)A
A is correct. A view (ie. the presentation of data) knows how to present the data and so
can be replaced with another view without any impact on the data representation.
B is incorrect. This allows plug and play between back end logic and the front end.
D is incorrect. This allows plug and play between the data container (the DB) and data
requestor.
26)B,C,D
An attribute element describes the attribute for a tag. Following is its definition.
<!ELEMENT attribute (name, required? , rtexprvalue?, type?, description?) >
27)C
28)A,B,E
29)D
30)B,D
Calling getServletConfig() from the init() method returns the ServletConfig object for this
servlet and calling getInitParameter(...) on the ServletConfig object returns the value of
that parameter.
Questions on Deployment Descriptor
1. Which of the following files is the correct name and location of deployment
descriptor of a web application. Assume that the web application is rooted at
\doc-root. Select the one correct answer
A. \doc-root\dd.xml
B. \doc-root\web.xml
C. \doc-root\WEB-INF\web.xml
D. \doc-root\WEB_INF\dd.xml
E. \doc-root\WEB-INF\dd.xml
F. \doc-root\WEB_INF\web.xml
G. \doc-root\WEB-INF\lib\dd.xml
H. \doc-root\WEB-INF\classes\dd.xml
3. Which of these is true about deployment descriptors. Select the one correct
answer.
A. The order of elements in deployment descriptor is not important. The
elements can follow any order.
B. The elements of deployment descriptor are case insensitive.
C. The servlet-mapping element, if defined, must be included within the
servlet element.
D. The web-app element must include the servlet element.
12. Which of the follwing are mandatory elements within the filter element. Select two
correct answers.
A. filter-name
B. name
C. value
D. filter-class
E. init-param
13. Which of these is not a valid value for dispatcher element of filter-mapping.
Select the one correct answer.
A. FORWARD
B. RESPONSE
C. INCLUDE
D. ERROR
14. Which of these is not correct about the filter-mapping element of web-app. Select
the one correct answer.
A. filter-name element must be present in the filter-mapping element.
B. Either url-pattern or servlet-name must be present in the filter-mapping
element.
C. dispatcher element can be declared zero to three times in the filter-
mapping element.
D. filter-name element in the filter-mapping should be same as the
corresponding filter-name element in the filter element of deployment
descriptor.
A small note here - In the real exam, there will be less questions of type fill in the
blanks, as compared to these set of questions. Also the real exam questions will
1. Which of the following is legal JSP syntax to print the value of i. Select the one
correct answer
A. <%int i = 1;%>
<%= i; %>
B. <%int i = 1;
i; %>
C. <%int i = 1%>
<%= i %>
D. <%int i = 1;%>
<%= i %>
E. <%int i = 1%>
<%= i; %>
2. A JSP page called test.jsp is passed a parameter name in the URL using
http://localhost/test.jsp?name="John". The test.jsp contains the following code.
3. Which of the following correctly represents the following JSP statement. Select
the one correct answer.
<%=x%>
A. <jsp:expression=x/>
B. <jsp:expression>x</jsp:expression>
C. <jsp:statement>x</jsp:statement>
D. <jsp:declaration>x</jsp:declaration>
E. <jsp:scriptlet>x</jsp:scriptlet>
4. Which of the following correctly represents the following JSP statement. Select
the one correct answer.
<%x=1;%>
A. <jsp:expression x=1;/>
B. <jsp:expression>x=1;</jsp:expression>
C. <jsp:statement>x=1;</jsp:statement>
D. <jsp:declaration>x=1;</jsp:declaration>
E. <jsp:scriptlet>x=1;</jsp:scriptlet>
5. What gets printed when the following JSP code is invoked in a browser. Select
the one correct answer.
<%= if(Math.random() < 0.5) %>
hello
<%= } else { %>
hi
<%= } %>
A. The browser will print either hello or hi based upon the return value of
random.
B. The string hello will always get printed.
C. The string hi will always get printed.
D. The JSP file will not compile.
6. Which of the following are correct. Select the one correct answer.
A. JSP scriptlets and declarations result in code that is inserted inside the
_jspService method.
B. The JSP statement <%! int x; %> is equivalent to the statement
<jsp:scriptlet>int x;</jsp:scriptlet%>.
C. The following are some of the predefined variables that maybe used in
JSP expression - httpSession, context.
D. To use the character %> inside a scriptlet, you may use %\> instead.
7. What gets printed when the following is compiled. Select the one correct answer.
<% int y = 0; %>
<% int z = 0; %>
<% for(int x=0;x<3;x++) { %>
<% z++;++y;%>
<% }%>
A. 0
B. 1
C. 2
D. 3
E. The program generates compilation error.
8. Which of the following JSP variables are not available within a JSP expression.
Select the one correct answer.
A. out
B. session
C. request
D. response
E. httpsession
F. page
9. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
Which of the following statements may be used to print the value of color
property of the bean. Select the one correct answer.
A. <jsp:getColor bean="fruit"/>
B. <jsp:getProperty id="fruit" property="color"/>
C. <jsp:getProperty bean="fruit" property="color"/>
D. <jsp:getProperty name="fruit" property="color"/>
E. <jsp:getProperty class="Fruit" property="color"/>
10. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
Which of the following statements may be used to set the of color property of the
bean. Select the one correct answer.
A. <jsp:setColor id="fruit" property="color" value="white"/>
B. <jsp:setColor name="fruit" property="color" value="white"/>
C. <jsp:setValue name="fruit" property="color" value="white"/>
D. <jsp:setProperty name="fruit" property="color" value="white">
E. <jsp:setProperty name="fruit" property="color" value="white"/>
F. <jsp:setProperty id="fruit" property="color" value="white">
11. A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
What happens when the following statement is executed. Select the one correct
answer.
<jsp:setProperty name="fruit" property="*"/>
A. This is incorrect syntax of <jsp:setProperty/> and will generate a
compilation error. Either value or param must be defined.
B. All the properties of the fruit bean are initialized to a value of null.
C. All the properties of the fruit bean are assigned the values of input
parameters of the JSP page that have the same name.
D. All the properties of the fruit bean are initialized to a value of *.
12. Is the following statement true or false. If the isThreadSafe attribute of the page
directive is false, then the generated servlet implements the SingleThreadModel
interface.
13. Which of the following represents a correct syntax for usebean. Select the two
correct answers.
A. <jsp:usebean id="fruit scope ="page"/>
B. <jsp:usebean id="fruit type ="String"/>
C. <jsp:usebean id="fruit type ="String" beanName="Fruit"/>
D. <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/>
15. Which of the following statements are true for <jsp:usebean>. Select the two
correct answers.
A. The id attribute must be defined for <jsp:usebean>.
B. The scope attribute must be defined for <jsp:usebean>.
C. The class attribute must be defined for <jsp:usebean>.
D. The <jsp:usebean> must include either type or class attribute or both.
16. Which of these are legal attributes of page directive. Select the two correct
answers.
A. include
B. scope
C. errorPage
D. session
E. debug
17. Which of the following represents the XML equivalent of this statement <%@
include file="a.jsp"%> . Select the one correct statement
A. <jsp:include file="a.jsp"/>
B. <jsp:include page="a.jsp"/>
C. <jsp:directive.include file="a.jsp"/>
D. There is no XML equivalent of include directive.
18. Assume that you need to write a JSP page that adds numbers from one to ten,
and then print the output.
Which statement when placed at the location XXX can be used to compute the
sum. Select the one correct statement
19. Now consider the same JSP example as last question. What must be added at
the location YYY to print the sum of ten numbers. Select the one correct
statement
A. <% sum %>
B. <% sum; %>
C. <%= sum %>
D. <%= sum; %>
20. JSP pages have access to implicit objects that are exposed automatically. One
such object that is available is request. The request object is an instance of
which class?
A. HttpRequest
B. ServletRequest
C. Request
D. HttpServletRequest
21. JSP pages have access to implicit objects that are exposed automatically. Name
the implicit object that is of type HttpSession.
A. session
B. application
C. httpSession
D. httpsession
22. A Java bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>
What is the effect of the following statement.
<jsp:setproperty name="fruit" property="color"/>
Select the one correct answer.
A. An error gets generated because the value attribute of setAttribute is not
defined.
B. The color attribute is assigned a value null.
C. The color attribute is assigned a value "".
D. If there is a non-null request parameter with name color, then its value
gets assigned to color property of Java Bean fruit.
23. The page directive is used to convey information about the page to JSP
container. Which of these are legal syntax of page directive. Select the two
correct statement
A. <% page info="test page" %>
B. <%@ page info="test page" session="false"%>
C. <%@ page session="true" %>
D. <%@ page isErrorPage="errorPage.jsp" %>
E. <%@ page isThreadSafe=true %>
24. Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>
A. contentType
B. generateXML
C. type
D. outputXML
26. A JSP page uses the java.util.ArrayList class many times. Instead of referring the
class by its complete package name each time, we want to just use ArrayList.
Which attribute of page directive must be specified to achieve this. Select the one
correct answer.
A. extends
B. import
C. include
D. package
E. classpath
27. Which of these are true. Select the two correct answers.
A. The default value of isThreadSafe attribute of page directive is true.
B. If isThreadSafe attribute of page directive is set to true, then JSP
container dispatches request for the page sequentially.
C. When isThreadSafe attribute of page directive is set to true, a thread is
created for each request for the page.
D. Setting isThreadSage attribute to true for JSP pages, can lead to poor
performance.
28. Which of the following are examples of JSP directive. Select the two correct
answers.
A. include
B. exclude
C. import
D. taglibrary
E. servlet
F. page
29. Which of these is true about include directive. Select the one correct answer.
A. The included file must have jspf extension.
B. The XML syntax of include directive in <jsp:include file="fileName"/> .
C. The content of file included using include directive, cannot refer to
variables local to the original page.
D. When using the include directive, the JSP container treats the file to be
included as if it was part of the original file.
30. Name the implicit variable available to JSP pages that may be used to access all
the other implicit objects.
A. page
B. pageContext
C. context
D. object
E. jspPave
1. d. When using scriptlets (that is code included within <% %>), the included code
must have legal Java syntax. So the first statement must end with a semi-colon.
The second statement on the other hand is a JSP expression. So it must not end
with a semi colon.
2. b. JSP declarations do not have access to automatically defined variables like
request, response etc.
3. b. The XML syntax for JSP expression is <jsp:expression>Java
expression</jsp:expression>
4. e. The XML syntax for JSP scriptlets is <jsp:scriptlet>Java code</jsp:scriptlet>
5. d. The if statement, else statement and closing parenthesis are JSP scriptlets
and not JSP expressions. So these should be included within <% } %>
6. d. JSP declarations are inserted outside of _jspService method. Hence a is
incorrect. The JSP statement <%!int a;%> is equivalent to <jsp:declaration>int
x;</jsp:declaration>. Hence b is incorrect. The predefined variables that are
available within the JSP expression are session and pageContext, and not
httpSession and context. Hence c is incorrect.
7. c. After the for loop z and y are both set to 3. The else satement gets evaluated,
and 2 gets printed in the browser.
8. e. There is no such variable as httpsession.
9. jsp:getProperty takes two attributes - name and property. The name attribute
must match the id attribute of jsp:usebean.
10. e. The jsp:setProperty takes three attributes - name, property and value. Also the
jsp:setProperty must end with />.
11. c. Using * for property is legal syntax. Bean properties are associated with
identically named input parameters.
12. true. The page directive is defined as <%@page isThreadSafe="false"%>
13. b,c.
14. a. The default scope of the declared bean is page.
15. a,d. The scope and class attributes are not required. But either class or type
must be defined.
16. c,d. The following are legal attributes of page directive - import, isThreadSafe,
session, contentType, autoFlush, extends, info, errorPage, isErrorPage,
language.
17. c. <jsp:directive.include> is the XML equivalent of include directive.
18. b. As this is a a Java statement it needs to be included with <% and %>, and it
needs to end in semi-colon.
19. c. As this is a a Java expression it needs to be included with <%= and %>, and it
should not end in semi-colon.
20. d. request is an instance of HttpServletRequest
21. a. Implicit object session is of type HttpSession.
22. d. This is a legal syntax to set a property of JavaBean. The value attribute of
setProperty is optional.
23. b,c. The option a is incorrect because page directive must be included within
<%@ . d is incorrect because the value of isErrorPage attribute must be boolean.
e is incorrect because, the value true is not within quotes.
24. b. Except the import attribute of page directive, all the other attributes of page
directive cannot be specified more than once. In this example session attribute is
specified twice.
25. a. contentType attribute is used to generate XML. The syntax will look like -
<%@page contentType="text/xml"/>
26. B. The syntax will look like -
<%@page import="java.util.ArrayList"/>
27. a,c. The default value of isThreadSafe attribute is true. So a is correct. If
isThreadSafe is set to false, then JSP container processes request sequentially,
and this leads to poor performance. Hence b and d are incorrect.
28. a,f. include, taglib and page are examples of JSP directives. The JSP directives
have this syntax -
<%@directive attribute="value" %>
29. d. It is not required that the included file has jspf extension. Hence a is incorrect.
The XML syntax of include directive is <jsp:directive.include>
30. b. This pageContext object is an instance of type javax.servlet.jsp.PageContext,
and provides methods like getPage(), getRequest(), etc. to access other input
variables.
1. When implementing a tag, if the tag just includes the body verbatim, or if it does
not include the body, then the tag handler class must extend the
BodyTagSupport class. Is this statement true of false.
4. A JSP file that uses a tag library must declare the tag library first. The tag library
is defined using the taglib directive - <%= taglib uri="..." prefix="..."%> Which of
the following specifies the correct purpose of prefix attribute. Select the one
correct answer.
A. The prefix defines the name of the tag that may be used for a tag library.
B. The prefix attribute defines the location of the tag library descriptor file.
C. The prefix attribute should refer to the short name attribute of the tag
library file that is defined by the uri attribute of taglib directive.
D. The prefix attribute is used in front of a tagname of a tag defined within the
tag library.
5. A JSP file uses a tag as <myTaglib:myTag>. The myTag element here should be
defined in the tag library descriptor file in the tag element using which element.
Select the one correct answer.
A. tagname
B. name
C. tag
D. prefix
6. Which of the elements defined within the taglib element of taglib descriptor file
are required. Select the two correct answers.
A. tlib-version
B. short-name
C. uri
D. display-name
7. Which of the elements defined within the taglib element of taglib descriptor file
are required. Select the two correct answers.
A. name
B. description
C. validator
D. tag-class
E. display-name
8. Name the element within the tag element that defines the name of the class that
implements the functionality of tag. Select the one correct answer.
A. class-name
B. tag
C. class
D. tag-class
E. tei-class
9. Which of these are legal return types of the doStartTag method defined in a class
that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE
10. Which of these are legal return types of the doAfterBody method defined in a
class that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_AGAIN
D. EVAL_BODY_AGAIN
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_AGAIN
H. SKIP_BODY_AGAIN
11. Which of these are legal return types of the doEndTag method defined in a class
that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE
Questions on Servlets
1. The method getWriter returns an object of type PrintWriter. This class has println
methods to generate output. Which of these classes define the getWriter
method? Select the one correct answer.
A. HttpServletRequest
B. HttpServletResponse
C. ServletConfig
D. ServletContext
2. Name the method defined in the HttpServletResponse class that may be used to
set the content type. Select the one correct answer.
A. setType
B. setContent
C. setContentType
D. setResponseContentType
3. Which of the following statement is correct. Select the one correct answer.
A. The response from the server to a HEAD request consists of status line,
content type and the document.
B. The response from the server to a GET request does not contain a
document.
C. The setStatus method defined in the HttpServletRequest class takes an int
as an argument and sets the status of Http response
D. The HttpServletResponse defines constants like SC_NOT_FOUND that
may be used as a parameter to setStatus method.
6. Which of the following statements are correct about the status of the Http
response. Select the one correct answer.
A. A status of 200 to 299 signifies that the request was successful.
B. A status of 300 to 399 are informational messages.
C. A status of 400 to 499 indicates an error in the server.
D. A status of 500 to 599 indicates an error in the client.
A. getStream
B. getOutputStream
C. getBinaryStream
D. getWriter
8. To send text output in a response, the following method of HttpServletResponse
may be used to get the appropriate Writer/Stream object. Select the one correct
answer.
A. getStream
B. getOutputStream
C. getBinaryStream
D. getWriter
9. Is the following statement true or false. URL rewriting may be used when a
browser is disabled. In URL encoding the session id is included as part of the
URL.
10. Name the class that includes the getSession method that is used to get the
HttpSession object.
A. HttpServletRequest
B. HttpServletResponse
C. SessionContext
D. SessionConfig
11. 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.
13. Which HTTP method gets invoked when a user clicks on a link? Select the one
correct answer.
A. GET method
B. POST method
C. HEAD method
D. PUT method
14. When using HTML forms which of the folowing is true for POST method? Select
the one correct answer.
A. POST allows users to bookmark URLs with parameters.
B. The POST method should not be used when large amount of data needs
to be transferred.
C. POST allows secure data transmission over the http method.
D. POST method sends data in the body of the request.
15. Which of the following is not a valid HTTP/1.1 method. Select the one correct
answer.
A. CONNECT method
B. COMPARE method
C. OPTIONS method
D. TRACE method
16. Name the http method used to send resources to the server. Select the one
correct answer.
A. FTP methodd
B. PUT method
C. WRITE method
D. COPY method
17. Name the http method that sends the same response as the request. Select the
one correct answer.
A. DEBUG method
B. TRACE method
C. OPTIONS method
D. HEAD method
18. Which three digit error codes represent an error in request from client? Select the
one correct answer.
A. Codes starting from 200
B. Codes starting from 300
C. Codes starting from 400
D. Codes starting from 500
19. Name the location of compiled class files within a war file? Select the one correct
answer.
A. /META-INF/classes
B. /classes
C. /WEB-INF/classes
D. /root/classes
Answers to questions on Servlets
100-199 Informational
1. What gets printed when the following expression is evaluated? Select the one
correct answer.
${(1==2) ? 4 : 5}
A. 1
B. 2
C. 4
D. 5
2. What gets printed when the following expression is evaluated? Select the one
correct answer.
${4 div 5}
A. 0
B. 0.8
C. 1
D. -1
3. What gets printed when the following expression is evaluated? Select the one
correct answer.
${12 % 4}
A. 0
B. 3
C. 8
D. 16
4. What is the effect of executing the following JSP statement, assuming a class
with name Employee exists in classes package.
5. What is the effect of evaluation of following expression? Select the one correct
answer.
${(5*5) ne 25}
A. true
B. false
C. 25
D. The expression does not compile as ne is not a valid operator.
6. What is the effect of evaluation of following expression? Select the one correct
answer.
${'cat' gt 'cap'}
A. true
B. false
C. catcap
D. The expression does not compile as gt operator cannot be applied on
strings.
7. How many numbers are printed, when the following JSTL code fragment is
executed? Select the one correct answer.
A. 1
B. 5
C. 6
D. 11
8. What gets printed when the following JSTL code fragment is executed? Select
the one correct answer.
A. The JSTL code does not compile as attribute for if tag are not correct.
B. true
C. false
D. Nothing gets printed.
9. What gets printed when the following JSTL code fragment is executed? Select
the one correct answer.
A. The JSTL code does not compile as an attribute for forEach tag is not
correct.
B. 0
C. 2
D. ABC
E. Nothing gets printed as c.out statement does not get executed.
10. How many numbers gets printed when the following JSTL code fragment is
executed? Select the one correct answer.
11. Which numbers gets printed when the following JSTL code fragment is
executed? Select the two correct answers.
12. Which numbers gets printed when the following JSTL code fragment is
executed? Select the two correct answers.
13. Which number gets printed when the following JSTL code fragment is executed?
Select the one correct answers.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" varStatus="status">
<c:if test="${status.first}">
<c:out value="${status.index}" default="abc"/>
</c:if>
</c:forEach>
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.
14. Which of these represent the correct path for the core JSTL library in JSTL
version 1.1? Select the one correct answer.
A. http://java.sun.com/jsp/jstl/core
B. http://java.sun.com/jsp/core
C. http://java.sun.com/core
D. http://java.sun.com/jsp/jstl1.1/core