SCWCD-20 05/13/2008

A JSP page can receive context initialization parameters through the deployment descriptor of the web application.

a True

b False

Answer: a

When writing a TLD, which tags would you use to surround fnName(int num), a Java method declared in a separate class?

a <function-signature></function-signature>

b <function-name></function-name>

c <method-class></method-class>

d <method-signature></method-signature>

e <function-class></function-class>

Answer: a

Which of the options locate the bean equivalent to the following action? (Select three)

<jsp:useBean id="address" class="AddressBean" scope="request" />

a request.getAttribute("address");

b request.getParameter("address");

c getServletContext().getRequestAttribute("address");

d pageContext.getAttribute("address",PageContext.REQUEST_SCOPE);

e pageContext.getRequest().getAttribute("address");

f pageContext.getRequestAttribute("address");

g pageContext.getRequestParameter("address");

Answers: a, d, and e


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)

a <mylib:printReport/>

b <mylib:printReport department="finance"/>

c <mylib:printReport attribute="department" value="finance"/>

d <mylib:printReport attribute="department"


e <mylib:printReport>

<jsp:attribute name="department" value="finance" />


Answers: a and b


Which of the following methods is never called for handler classes that implement only the Tag interface? (Select one)

a setParent()

b doStartTag()

c doAfterbody()

d doEndTag()

Answer: c

Which of the following values is invalid inside a SimpleTag’s <bodycontent> subelement? (Select one)


b scriptless

c tagdependent

d empty

Answer: a

You are designing an application that is required to display the data to users through HTML interfaces. It also has to feed the same data to other systems through XML as well as WAP interfaces. Which design pattern would be appropriate in this situation? (Select one)

a Interface Factory

b Session Facade

c Transfer Object

d Model-View-Controller

e Factory

Answer: d

SCWCD-19 05/13/2008

Consider the following HTML page code:
 <form name="data" action="/servlet/DataServlet" method="POST">
 <input type="text" name="name">
 <input type="submit" name="submit">
 Identify the two methods that can be used to retrieve the value of the name parameter when the form is submitted.

a getParameter("name");

b getParameterValue("name");

c getParameterValues("name");

d getParameters("name");

e getValue("name");

f getName();

Answers: a and c


Your web application, named simpletax, depends on a third-party JAR file named taxpackage.jar. Where would you keep this file? (Select one)

a simpletax

b simpletax/WEB-INF

c simpletax/WEB-INF/classes

d simpletax/WEB-INF/lib

e simpletax/WEB-INF/jars

f simpletax/WEB-INF/thirdparty

Answer: d

Which deployment descriptor element is used to specify a ServletContext- Listener? (Select one)

a <context-listener>

b <listener>

c <servlet-context-listener>

d <servletcontextlistener>

e <servletcontext-listener>

Answer: b

Which of the following method calls will ensure that a session will never be expunged by the servlet container? (Select one)

a session.setTimeout(0);

b session.setTimeout(-1);

c session.setTimeout(Integer.MAX_VALUE);

d session.setTimeout(Integer.MIN_VALUE);

e None of these.

Answer: e

Which of the following deployment descriptor elements is used for specifying the authentication mechanism for a web application? (Select one)

a security-constraint

b auth-constraint

c login-config

d web-resource-collection

Answer: c

  Which of the following correctly declares that the current page is an error page and also enables it to take part in a session? (Select one)

a <%@ page pageType="errorPage" session="required" %>

b <%@ page isErrorPage="true" session="mandatory" %>

c <%@ page errorPage="true" session="true" %>

d <%@ page isErrorPage="true" session="true" %>

e None of the above.

Answer: d

SCWCD-18 05/13/2008

Which two of the following expressions won’t return the header’s accept field?

a ${header.accept}

b ${header[accept]}

c ${header['accept']}

d ${header["accept"]}

e ${header.'accept'}

Answers: b and e


Consider the following code:

<jsp:useBean id="address" class="AddressBean" scope="session" />

state = <jsp:getProperty name="address" property="state" />

Which of the following are equivalent to the third line above? (Select three)

a <% state = address.getState(); %>

b <% out.write("state = "); out.print(address.getState()); %>

c <% out.write("state = "); out.print(address.getstate()); %>

d <% out.print("state = " + address.getState()); %>

e state = <%= address.getState() %>

f state = <%! address.getState(); %>

Answers: b, d, and e

Consider the following <taglib> element, which appears in a deployment descriptor of a web application:

Which of the following correctly specifies the use of the above tag library in a JSP page? (Select one)

a <%@ taglib uri="/accounting" prefix="acc"%>

b <%@ taglib uri="/acc" prefix="/accounting"%>

c <%@ taglib name="/accounting" prefix="acc"%>

d <%@ taglib library="/accounting" prefix="acc"%>

e <%@ taglib name="/acc" prefix="/accounting"%>

Answer: a

At a minimum, which of the following interfaces are required to create an iterative custom tag? (Select one)

a Tag

b Tag and IterationTag

c Tag, IterationTag, and BodyTag

d TagSupport

e BodyTagSupport

Answer: b


Which of the following methods need to be invoked in a SimpleTag to provide iterative processing? (Select one)

a setDynamicAttribute()

b getParent()

c getJspBody()

d doTag()

e getJspContext()

Answer: d


What are the benefits of using the Business Delegate pattern? (Select three)

a It implements the business service functionality locally to improve performance.

b It shields the clients from the details of the access mechanism, such as CORBA or

RMI, of the business services.

c It shields the clients from changes in the implementation of the business services.

d It provides the clients with a uniform interface to the business services.

e It reduces the number of remote calls and reduces network overhead.

Answers: b, c, and d

SCWCD-17 05/13/2008

Your servlet class depends on a utility class named Where would you keep the TaxUtil.class file? (Select one)


b WEB-INF/classes

c WEB-INF/lib

d WEB-INF/jars

e WEB-INF/classes/com/abc

Answer: e

Which method is used to retrieve an initialization parameter from a Servlet- Context? (Select one)

a Object getInitParameter(int index)

b Object getParameter(int index)

c Object getInitParameter(String name)

d String getInitParameter(String name)

e String getParameter(String name)

Answer: d


Which of the following methods will expunge a session object? (Select one)

a session.invalidate();

b session.expunge();

c session.destroy();

d session.end();

e session.close();

Answer: a


Identify the authentication mechanisms that are built into the HTTP specification. (Select two)

a Basic

b Client-Cert


d Digest

e Client-Digest


Answers: a and d

Write the name of the method that you can use to initialize variables declared in a JSP declaration in the space provided. (Write only the name of the method. Do

not write the return type, parameters, or parentheses.)

a [_____________]

Answer: jspInit

The implicit variable config in a JSP page refers to an object of type: (Select one)

a javax.servlet.PageConfig

b javax.servlet.jsp.PageConfig

c javax.servlet.ServletConfig

d javax.servlet.ServletContext

Answer: c

Consider the contents of two JSP files: File 1: test1.jsp <html><body> <% pageContext.setAttribute("ninetyNine", new Integer(99)); %> //1 </body></html> File 2: test2.jsp The number is <%= pageContext.getAttribute("ninetyNine") %> Which of the following, when placed at line //1 in the test1.jsp file, will allow the test2.jsp file to print the value of the attribute when test1.jsp is requested? (Select one)

a <jsp:include page="test2.jsp" />

b <jsp:forward page="test2.jsp" />

c <%@ include file="test2.jsp" %>

d None of the above because objects placed in pageContext have the page scope

and cannot be shared with other components.

Answer: c

SCWCD-16 05/13/2008

Which tags tell the web container where to find your TLD file in your filesystem?

a <taglib-directory></taglib-directory>

b <taglib-uri></taglib-uri>

c <taglib-location></taglib-location>

d <tld-directory></tld-directory>

e <taglib-name></taglib-name>

Answer: c

Which of the following gets or sets the bean in the ServletContext container object? (Select one)

a <jsp:useBean id="address" class="AddressBean" />

b <jsp:useBean id="address" class="AddressBean" scope="application" />

c <jsp:useBean id="address" class="AddressBean" scope="servlet" />

d <jsp:useBean id="address" class="AddressBean" scope="session" />

e None of the above.

Answer: b


Which of the following is a valid taglib directive? (Select one)

a <%@ taglib prefix="java" uri="sunlib"%>

b <%@ taglib prefix="jspx" uri="sunlib"%>

c <%@ taglib prefix="jsp" uri="sunlib"%>

d <%@ taglib prefix="servlet" uri="sunlib"%>

e <%@ taglib prefix="sunw" uri="sunlib"%>

f <%@ taglib prefix="suned" uri="sunlib"%>

Answer: f

Which of the following interfaces are required at a minimum to create a simple custom tag with a body? (Select one)

a Tag

b Tag and IterationTag

c Tag, IterationTag, and BodyTag

d TagSupport

e BodyTagSupport

Answer: a

If placed inside the body of a custom tag, which of the following statements won’t produce “9”? (Select one)

a ${3 + 3 + 3}

b "9"

c <c:out value="9">

d <%= 27/3 %>

Answer: d


Which of the following statements are correct? (Select two)

a The Transfer Object pattern ensures that the data is not stale at the time of use.

b It is wise to make the Transfer Object immutable if the Transfer Object represents

read-only data.

c Applying the Transfer Object pattern on EJBs helps to reduce the load on enterprise


d A Transfer Object exists only on the server side.

Answers: b and c

You need to send a GIF file to the browser. Which of the following lines should be called after (or before) a call to response.getOutputStream()? (Select one)

a response.setContentType("image/gif"); Before

b response.setContentType("image/gif"); After

c response.setDataType("image/gif"); Before

d response.setDataType("image/gif"); After

e response.setStreamType("image/gif"); Before

f response.setStreamType("image/gif"); After

Answer: a

SCWCD-15 05/13/2008

Which of the following lines would initialize the out variable for sending a Microsoft Word file to the browser? (Select one)

a PrintWriter out = response.getServletOutput();

b PrintWriter out = response.getPrintWriter();

c OutputStream out = response.getWriter();

d PrintWriter out = response.getOuputStream();

e OutputStream out = response.getOuputStream();

f ServletOutputStream out = response.getServletOutputStream();

Answer: e


What file is the deployment descriptor of a web application named BankApp stored in? (Select one)

a BankApp.xml

b bankapp.xml

c server.xml

d deployment.xml

e WebApp.xml

f web.xml

Answer: f


Which method is used to retrieve an attribute from a ServletContext? (Select one)

a String getAttribute(int index)

b String getObject(int index)

c Object getAttribute(int index)

d Object getObject(int index)

e Object getAttribute(String name)

f String getAttribute(String name)

g String getObject(String name)

Answer: e

Which of the following methods will be invoked on a session attribute that implements appropriate interfaces when the session is invalidated? (Select one)

a sessionDestroyed of HttpSessionListener

b attributeRemoved of HttpSessionAttributeListener

c valueUnbound of HttpSessionBindingListener

d sessionWillPassivate of HttpSessionActivationListener

Answer: c

Which of the following actions would you take to prevent your web site from being attacked? (Select three)

a Block network traffic at all the ports except the HTTP port.

b Audit the usage pattern of your server.

c Audit the Servlet/JSP code.

d Use HTTPS instead of HTTP.

e Design and develop your web application using a software engineering methodology.

f Use design patterns.

Answers: a, c, and d


Which of the following exceptions may be thrown by the _jspService() method? (Select one)

a javax.servlet.ServletException

b javax.servlet.jsp.JSPException

c javax.servlet.ServletException and javax.servlet.jsp.JSPException

d javax.servlet.ServletException and

e javax.servlet.jsp.JSPException and

Answer: d


Which of the following implicit objects can you use to store attributes that need to be accessed from all the sessions of a web application? (Select two)

a application

b session

c request

d page

e pageContext

Answers: a and e


Identify the JSP equivalent of the following code written in a servlet. (Select one)

RequestDispatcher rd = request.getRequestDispatcher("world.jsp");

rd.forward(request, response);

a <jsp:forward page="world.jsp"/>

b <jsp:action.forward page="world.jsp"/>

c <jsp:directive.forward page="world.jsp"/>

d <%@ forward file="world.jsp"%>

e <%@ forward page="world.jsp"%>

Answer: a

SCWCD-14 04/20/2008

Which of the following implicit objects is not available to a JSP page by default?

(Select one)

a application

b session

c exception

d config

Answer: c


Which of the following is a correct way to pass a parameter equivalent to the

query string user=mary at request time to an included component? (Select one)

a <jsp:include page="other.jsp" >

<jsp:param paramName="user" paramValue="mary" />


b <jsp:include page="other.jsp" >

<jsp:param name="mary" value="user" />


c <jsp:include page="other.jsp" >

<jsp:param value="mary" name="user" />


d <jsp:include page="other.jsp" >

<jsp:param param="user" value="mary"/>


e <jsp:include page="other.jsp" >

<jsp:param user="mary" />


Answer: c


Which of the following variables is not available for use in EL expressions?

a param

b cookie

c header

d pageContext

e contextScope

Answer: e


Which of the following are valid uses of the <jsp:useBean> action? (Select two)

a <jsp:useBean id="address" class="AddressBean" name="address" />

b <jsp:useBean id="address" class="AddressBean"

type="AddressBean" />

c <jsp:useBean id="address" beanName="AddressBean"

class="AddressBean" />

d <jsp:useBean id="address" beanName="AddressBean"

type="AddressBean" />

Answers: b and d


Which of the following is a valid taglib directive? (Select one)

a <% taglib uri="/stats" prefix="stats" %>

b <%@ taglib uri="/stats" prefix="stats" %>

c <%! taglib uri="/stats" prefix="stats" %>

d <%@ taglib name="/stats" prefix="stats" %>

e <%@ taglib name="/stats" value="stats" %>

Answer: b


Consider the following code in a JSP page:

<% String message = "Hello "; %>


How are you?

<% message = message + "World! " %>


<%= message %>

If doStartTag() returns EVAL_BODY_BUFFERED and doAfterBody() clears

the buffer by calling bodyContent.clearBody(), what will be the output of

the above code? (Select one)

a Hello

b Hello How are you?

c Hello How are you? World!

d Hello World!

e How are you World!

Answer: d


Consider the following TLD excerpt:











If the name of the tag is tagname and its prefix is pre, which of the following JSP

statements is valid?
a <pre:tagname color="yellow" size=${sizenum} />

b <pre:tagname size="18" color="red"> </pre:tagname>

c <pre:tagname color="${colorname}" size="22" font="verdana"></


d <pre:tagname color="green" size="30">font="Times New Roman"</


e <pre:tagname color="${colorname}" size="18"></pre>

Answer: c


Which of the following are the benefits of using the Transfer Object design pattern?

(Select two)

a It improves the response time for data access.

b It improves the efficiency of object operations.

c It reduces the network traffic.

d It reduces the coupling between the data access module and the database.

Answers: a and c

SCWCD-13 04/20/2008

Consider the following code for the doGet() method:

public void doGet(HttpServletRequest req,

HttpServletResponse res)


PrintWriter out = res.getWriter);



if(req.getParameter("name") == null)





Which of the following lines can be inserted at //1 so that the above code does

not throw any exception? (Select one)

a if ( ! res.isSent() )

b if ( ! res.isCommitted() )

c if ( ! res.isDone() )

d if ( ! res.isFlushed() )

e if ( ! res.flush() )

Answer: b


A web application is located in a directory named sales. Where should its

deployment descriptor be located? (Select one)

a sales

b sales/deployment

c sales/WEB

d sales/WEB-INF

e WEB-INF/sales


g WEB/sales

Answer: d



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? (Select one)

a This class will compile as is.

b This class will compile only if the attributeReplaced() method is added to it.

c This class will compile only if the attributeUpdated() method is added to it.

d This class will compile only if the attributeChanged() method is added to it.

Answer: b


Given these filter mapping declarations:


















in what order are the filters invoked for the following browser request?


a FilterOne, FilterThree

b FilterOne, FilterTwo, FilterThree

c FilterThree, FilterTwo

d FilterThree, FilterTwo

e FilterThree

f None of these filters are invoked.

Answer: d


Which of the following methods will be invoked on a session attribute that

implements HttpSessionBindingListener when the session is invalidated?

(Select one)

a sessionDestroyed

b valueUnbound

c attributeRemoved

d sessionInvalidated

Answer: b


Which one of the following must be done before authorization takes place?

(Select one)

a Data validation

b User authentication

c Data encryption

d Data compression

Answer: b


Which of the following methods is defined by the JSP engine? (Select one)

a jspInit()

b _jspService()

c _jspService(ServletRequest, ServletResponse)

d _jspService(HttpServletRequest, HttpServletResponse)

e jspDestroy()

Answer: d

SCWCD-12 04/14/2008

Which method is used to store file in the server ?  
     A    GET
     B    PUT
     C    POST
     D    HEAD


When a user clicks on a link in a page, which method will get invoked ?  
     A    POST    
     B    PUT       
     C    GET       
     D    HEAD


What method will get executed on clicking the following code.? 
<form method="GET" action="/TestServlet">
        <input type="text" name="name">
        <input type="submit" value="Submit">

     A    GET
     B    POST
     C    HEAD        
     D    PUT


Which character is used to separate the URI and query string ?  
     A    ?
     B    &
     C    =
     D    ;


What will be the output of the following code? Assume that all the variables are declared properly
String str= request.getDateHeader("Accept-Language");
     A    Compiler error
     B    An IO Exception is thrown
     C    Null
     D    An IllegalArgumentException thrown


To send binary output to response, which method of HttpServletResponse is used to get the Writer/ Stream object ?  
     A    getStream       
     B    getWriter       
     C    getBinaryOutputStream       
     D    getOutputStream       
     E    getBinaryStream 

<%@ page language ="java" session="false" isErrorPage="false" %>
which of the following JSP implicit object will not be available to the JSP page ? Select two
     A    session        
     B    request        
     C    application       
     D    exception      

A and D

Which among the following will compile ?
     A    <% int x=10 %>        
     B    <%= "hello how are you" %>       
     C    <%= "hello" ;% >       
     D    <%! int x=10 %>       

In a JSP custom tag , which method would you use to access JSP implicit variable that references application scope ?  
     A    PageContext.getOut()                      
     B    jspFactory.getPageContext()       
     C    TagSupport.getValue(String)       
     D    pageContext.getServletContext()       

Which method is used to retrieve objects from session?  
     A    getAttribute method of javax.servlet.ServletSession.  
     B    getAtrribute method of javax.servlet.HttpSession  
     C    getAttribute method of javax.servlet.http.Session
     D    getAttribute method of javax.servlet.http.HttpSession
     E    getAttribute method of javax.servlet.HttpSession


SCWCD-11 04/14/2008

What will be the output of the following JSP code? <html><body>  <%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %> </body></html>  
     A    Now b = 300       
     B    Now b = 600       
     C    The code will not compile       
     D    Now b = 30       
     E    Now b = 0


Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String value = getValue ();
        if (value == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");            

        response.sendRedirect ("test.jsp");
If the getValue () method returns null , which of the following statements are true?
     A    The code will work without any errors or exceptions        B    An IllegalStateException will be thrown       
     C    An IOException will be thrown       
     D    A NullPointerException will be thrown


Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
import javax.servlet.http.*:

public class MyServlet extends HttpServlet implements SingleThreadModel
    String myName;

    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  {
             PrintWriter out = res.getWriter();
  myName = req.getParameter("name");

   public void sayHello(PrintWriter out)  {
  out.println("Hello " + myName);
     A    MyServlet is thread safe       
     B    MyServlet is not thread safe because myName is an instance variable       
     C    MyServlet is not thread safe because MyServlet implements SingleThreadModel.       
     D    None of the above


Which of the following combinations regarding Design Patterns are correct?  
     A    Business Delegate - Reduces the coupling between presentation-tier clients and business services.       
     B    Data Access Object - Allows for Multiple Views using the same model       
     C    MVC - Enables easier migration to different persistence storage implementations.        
     D    Value Object - Reduces Network Traffic

A and D

Which of these is true about deployment descriptors. Select one correct answer.  
     A    The order of elements in deployment descriptor is important. The elements must follow a specific order.       
     B    The elements of deployment descriptor are not 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


Which element of the deployment descriptor includes the exception-type as a sub-element ?  
     A    <exception>       
     B    <error-page>       
     C    <error>       
     D    <exception_type>       
     E    <error_page>   


Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.

     A    <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>        
     B    <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> <location>/error.jsp</location> </error-page>        
     C    <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> </error-page>       
     D    <error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location> </error-page>    

A and D

Which element of the deployment descriptor of a web application includes the welcome-file-list element as a sub element.
     A    <welcome>       
     B    <welcome-files>       
     C    <list>       
     D    <web-app>       
     E    <context>   


Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select one correct answer.  
     A    <listener>MyClass</listener>       
     B    <listener> <listener-class>MyClass</listener-class></listener>       
     C    <listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener>       
     D    <><listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener>   


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; %>


    SCWCD Sets


    May 2008
    April 2008