You are on page 1of 7

Consider the following code in a tag handler class that extends TagSupport:

public int doStartTag()


{
//1
}
Which of the following can you use at //1 to get an attribute from the application scope?

getServletContext().getAttribute("name");
getApplication().getAttribute("name");
bodyContent.getApplicationAttribute("name");
pageContext.getAttribute("name",PageContext.APPLICATION_SCOPE);

If the doStartTag() method returns EVAL_BODY_BUFFERED one time and the doAfterBody() method
returns EVAL_BODY_BUFFERED five times, how many times will the setBodyContent() method be
called? Assume that the body of the tag is not empty.

Two
One
Five
Zero

Which of the following are the benefits of using the Value Object design pattern?(Select two)
It reduces the network traffic. (Google)
It improves the efficiency of object operations.
It reduces the coupling between the data access module and the database.
It improves the response time for data access. (Google)

Which one of the following must be done before authorization takes place?
Data encryption
Data compression
Data validation
User authentication

How can you make sure that none of the sessions associated with a web application will ever be
expunged by the servlet container?
session.setMaxInactiveInterval(–1);
Set the session timeout in the deployment descriptor to 0 or –1.
Set the session timeout in the deployment descriptor to –1.
Set the session timeout in the deployment descriptor to 65535.

What are the benefits of using the Data Access Object pattern? (Select two)
It allows the clients to access the data source through EJBs.
It increases the performance of data–accessing routines.
The type of the actual data source can be specified at deployment time.
The data clients are independent of the data source vendor API.

We can use the directive < %@ page buffer="8kb" % > to specify the size of the buffer when returning
EVAL_BODY_BUFFERED from doStartTag().
Is the above statement true or false?
TRUE
FALSE
You are given a tag library that has a tag named getMenu, which requires an attribute, subject. This
attribute can take a dynamic value.
Which of the following are correct uses of this tag?
< mylib:getMenu > < jsp:param subject="finance"/ > < /mylib:getMenu >< mylib:getMenu / >
< % String subject="HR";% >
< mylib:getMenu subject=" < %=subject% > "/ >
< tring subject="HR";
< mylib:getMenu subject=" < lubject "/ >

The users of your web application do not accept cookies. Which of the following statements are
correct?
You cannot maintain client state.
You cannot use URL rewriting.
URLs displayed by static HTML pages may not work properly.
You cannot set session timeout explicitly.

Which design pattern allows you to decouple the business logic, data representation, and data
presentation?
Value Object
Business Delegate
Bimodal Data Access
Model–View–Controller

Which of the following elements are required for a valid < taglib> element inweb.xml? (Select two)
uri
taglib–uri
taglib–location
location

Which of the following is not a requirement of a distributable web application?


It cannot depend on the notification events generated due to changes in the Servlet–Context attribute
list.
It cannot depend on the notification events generated when ServletContext is created or destroyed.
It cannot depend on the notification events generated when a session is activated or passivated.
It cannot depend on the notification events generated due to changes in the session attribute list.

Consider the following code:


public void doGet(HttpServletRequest req,HttpServletResponse res)
{
HttpSession session = req.getSession();
ServletContext ctx = this.getServletContext();
if(req.getParameter("userid") != null)
{
String userid = req.getParameter("userid");
//1
}
}
You want the userid parameter to be available only to requests that come from the same user. Which
of the following lines would you insert at //1?
req.setAttribute("userid", userid);
session.addAttribute("userid", userid);
ctx.addAttribute("userid", userid);
session.setAttribute("userid", userid);

Consider the following servlet code:


//...
public void service (HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
//1
}
Which of the following can be used at //1 to retrieve a JavaBean named addresspresent in the
application scope?
request.getAttribute("address",APPLICATION_SCOPE);
pageContext.getAttribute("address",APPLICATION_SCOPE);
application.getAttribute("address");
getServletContext().getAttribute("address");

Which of the following is a valid taglib directive?


< % @ taglib name="/stats" prefix="stats" % >
< % taglib uri="/stats" prefix="stats" % >
< %! taglib uri="/stats" prefix="stats" % >
< %@ taglib uri="/stats" prefix="stats" % >

Consider the following code, contained in a file called this.jsp:


< html > < body >
< jsp:useBean id="address" class="AddressBean" />
< jsp:setProperty name="address" property="*" />
< jsp:include page="that.jsp" />
< /body > < /html >
Which of the following is true about the AddressBean instance declared in the above code?

The bean instance will be available in that.jsp, and the that.jsp page can print the values of the beans
properties using
The bean instance will be available in that.jsp and the that.jsp page can print the values of the bean's
properties using < jsp:getProperty /> only if that.jsp also contains a < jsp:useBean/> declaration
identical to the one in this.jsp and before using < jsp:getProperty />
The bean instance may or may not be available in that.jsp, depending on the threading model
implemented by that.jsp
The bean instance will not be available in that.jsp

Consider the following HTML page code:


< html > < body >
< form name='data" action="/servlet/DataServlet" method="POST">
< input type="text" name="name">
< input type="submit" name="submit">
< /form >
< /body > < /html >
What are the two methods that can be used to retrieve the value of the name parameter when the
form is submitted?
getParameterValues("name");
getParameter("name");
getParameters("name");
getParameterValue("name");

Which of the following methods will be invoked when a ServletContext is destroyed?


contextDestroyed() of javax.servlet.HttpServletContextListener
contextDestroyed() of javax.servlet.ServletContextListener
contextDestroyed() of javax.servlet.http.HttpServletContextListener
contextDestroyed() of javax.servlet.http.ServletContextListener
Which of the following code options is the correct statement?.
< html > < body >
< %! int aNum=5 % >
The value of aNum is < % = aNum %>
< /body > < /html >
It will flag a compile–time error because of an incorrect declaration.
It will not flag any compile time or runtime errors and will not print anything to the output.
It will throw a runtime exception while executing the expression.
It will print "The value of aNum is 5" to the output.

Which of the following lines would initialize the out variable for sending a Microsoft Word file to
the browser?
OutputStream out = response.getWriter();
ServletOutputStream out = response.getServletOutputStream();
PrintWriter out = response.getOuputStream();
OutputStream out = response.getOuputStream();

Consider the following class:


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 of the following statements about the above class is correct?
This class will compile only if the attributeUpdated() method is added to it.
This class will compile as is.
This class will compile only if the attributeChanged() method is added to it.
This class will compile only if the attributeReplaced() method is added to it.

Which of the following is a valid taglib directive?


< %@ taglib name="/stats" prefix="stats" % >
< %! taglib uri="/stats" prefix="stats" % >
< %@ taglib uri="/stats" prefix="stats" % >
< % taglib uri="/stats" prefix="stats" % >

If the doStartTag() method returns EVAL_BODY_INCLUDE one time and thedoAfterBody() method
returns EVAL_BODY_AGAIN five times, how many times will the setBodyContent() method be called?
One
Zero
Two
Five

Which of the following is a valid taglib directive?


< %@ taglib prefix="sunw" uri="sunlib"% >
< %@ taglib prefix="jsp" uri="sunlib"% >
< %@ taglib prefix="servlet" uri="sunlib"% >
< %@ taglib prefix="suned" uri="sunlib"% >

None of the options is a valid taglib directive.

Which of the following methods will expunge a session object?


session.expunge();
session.end();
session.destroy();
session.invalidate();

Which of the following methods will be invoked on a session attribute that implements appropriate
interfaces when the session is invalidated?
valueUnbound of HttpSessionBindingListener
attributeRemoved of HttpSessionAttributeListener
sessionDestroyed of HttpSessionListener
sessionWillPassivate of HttpSessionActivationListener

Consider the following code contained in a file named this.jsp (the same asabove, except the fourth
line):
< html > < body >
< jsp:useBean id="address" class="AddressBean" />
< jsp:setProperty name="address" property="*" />
< %@ include file="that.jsp" % >
< /body > < /html >
Which of the following is true about the AddressBean instance declared in the above code?
The bean instance will be available in that.jsp and the that.jsp page can print the values of the bean's
properties using < jsp:getProperty /> only if that.jsp
also contains a < jsp:useBean /> declaration identical to the one in this.jsp and before using <
jsp:getProperty />
The bean instance will not be available in that.jsp
The bean instance may or may not be available in that.jsp, depending on the threading model
implemented by that.jsp
The bean instance will be available in that.jsp, and the that.jsp page can print the values of the beans
properties using

How is the SKIP_PAGE constant used?


doStartTag() can return it to skip the evaluation until the end of the current page.
doAfterBody() can return it to skip the evaluation until the end of the current page.
It is passed as a parameter to doEndTag() as an indication to skip the evaluation until the end of the
current page.
doEndTag() can return it to skip the evaluation until the end of the current page.
Which types of objects can be returned by PageContext.getOut()? (Select two)
An object of type BodyContent
An object of type HttpJspWriter
An object of type JspWriter
An object of type HttpServletOutputStream

Which of the following is not a valid sub–element of the element in a TLD?


< name >
< class >
< required >
< type >

Your web application, named Simpletax, depends on a third–party JAR file named taxpackage.jar.
Where would you keep this file?
simpletax/WEB–INF
simpletax/WEB–INF/classes
simpletax/WEB–INF/jars
simpletax/WEB–INF/lib

Consider the following < taglib > element, which appears in a deploymentdescriptor of a web
application:
< taglib >
< taglib–uri > /accounting < /taglib–uri >
< taglib–location > /WEB–INF/tlds/SmartAccount.tld < /taglib–location>
< taglib >
Which of the following correctly specifies the use of the above tag library in a JSP page?
< %@ taglib library="/accounting" prefix="acc"% >
< %@ taglib uri="/accounting" prefix="acc"% >
< %@ taglib name="/accounting" prefix="acc"% >
< %@ taglib uri="/acc" prefix="/accounting"% >

A web application is located in a directory named Sales. Where should its deployment descriptor be
located?
WEB–INF/sales
sales/WEB–INF
sales/deployment
sales/WEB

Which method is required for using the URL rewriting mechanism for implementing session
support?
HttpServletResponse.rewriteURL()
HttpServletRequest.rewriteURL()
HttpServletRequest.encodeURL()
HttpServletResponse.encodeURL()

Which deployment descriptor element is used to specify a ServletContext–Listener?


< servletcontextlistener >
< servlet–context–listener >
< context–listener >
< listener >

Which of the following elements can you use to import a tag library in a JSP document?
< jsp:root >
< jsp:taglib >
< jsp:directive.taglib >
< jsp:taglib.directive >

Which of the following is a valid return value for doAfterBody()?


SKIP_BODY
SKIP_PAGE
EVAL_PAGE
EVAL_BODY_INCLUDE

Which of the following method calls will ensure that a session will never be expunged by the servlet
container?
session.setTimeout(Integer.MAX_VALUE);
session.setTimeout(Integer.MIN_VALUE);
session.setTimeout(–1);
None of the answer

Which method in the HttpServlet class services the HTTP POST request?
servicePost(HttpServletRequest, HttpServletResponse)
doPOST(ServletRequest, ServletResponse)
doPost(HttpServletRequest, HttpServletResponse)
doPost(ServletRequest, ServletResponse)

You are given a tag library that has a tag named printReport. This tag may accept an attribute,
department, which cannot take a dynamic value.
Which of the following are correct uses of this tag? (Select two)
< mylib:printReport/ >
< mylib:printReport attribute="department" attribute–value="finance"/ >
< mylib:printReport department="finance"/ >
< mylib:printReport attribute="department" value="finance"/ >

You might also like