SCWCD-14

04/20/2008

1 Comment

 

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" />

</jsp:include>

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

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

</jsp:include>

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

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

</jsp:include>

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

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

</jsp:include>

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

<jsp:param user="mary" />

</jsp:include>

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

<test:world>

How are you?

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

</test: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:

<body-content>

empty

</body-content>

<attribute>

<name>color</name>

<rtexprvalue>true</rtexprvalue>

</attribute>

<dynamic-attributes>

true

</dynamic-attributes>

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"></

pre:tagname>

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

pre:tagname>

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

0 Comments

 

Consider the following code for the doGet() method:

public void doGet(HttpServletRequest req,

HttpServletResponse res)

{

PrintWriter out = res.getWriter);

out.println("<html><body>Hello</body></html>");

//1

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

{

res.sendError(HttpServletResponse.SC_UNAUTHORIZED);

}

}

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

f WEB-INF

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:

<filter-mapping>

<filter-name>FilterOne</filter-name>

<url-pattern>/admin/*</url-pattern>

<dispatcher>FORWARD</dispatcher>

</filter-mapping>

<filter-mapping>

<filter-name>FilterTwo</filter-name>

<url-pattern>/users/*</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>FilterThree</filter-name>

<url-pattern>/admin/*</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>FilterTwo</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

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

/admin/index.jsp

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

1 Comment

 

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

Answer
B

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

Answer
C

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">
</form>  

 
     A    GET
     B    POST
     C    HEAD        
     D    PUT

Answer
A

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

Answer
A

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

Answer
D

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 
    
Answer
D

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

Answer
A and D

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

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()       
         
Answer
D

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

Answer
D

 

SCWCD-11

04/14/2008

2 Comments

 

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

Answer
B

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

Answer
B

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

public class MyServlet extends HttpServlet implements SingleThreadModel
{
    String myName;

    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  {
    response.setContentType("text/plain");
             PrintWriter out = res.getWriter();
  myName = req.getParameter("name");
  sayHello(out);
  out.close();
    }

   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

Answer
A

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

Answer
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

Answer
A

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>   

Answer
B

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>    

Answer
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>   

Answer
D

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>   

Answer
B

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

Answer
D

 

SCWCD-10

04/14/2008

6 Comments

 

What will be the output of the following JSP code?

<% int a = 10; %>
<%! int a = 20; %>
<%! int b = 30; %>
The value of b multiplied by a is <%= b * a %>

·  A) The code will not compile
·  B) The value of b multiplied by a is 30
·  C) The value of b multiplied by a is 300
·  D) The value of b multiplied by a is 600
·  E) The value of b multiplied by a is 0

Answer
C
Since the local variable "a" has precedence over the global variable "a", the expression (b * a) evaluates as (30 *10), which equals 300

Consider the following code snippet of servlet code:

public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String dbValue = getValueFromDB ();
if (dbValue == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "DB Lookup Failed");
response.sendRedirect ("Form.jsp"); }
If the getValueFromDB () 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

Answer
B

Let's assume you are developing a custom tag handler using the BodyTag interface. The BodyTag interface extends the IterationTag interface by defining additional methods that allow a tag handler to evaluate its body content in a temporary buffer.

Upon execution, your tag handler returns the EVAL_BODY_BUFFERED return value from the doStartTag() method. In addition, your tag handler returns the EVAL_BODY_AGAIN value two times from the doAfterBody() method.

Based on this information, how many times will the setBodyContent() method be called by the JSP container?


·  A) Zero
·  B) One
·  C) Two
·  D) Three

Answer
B
Let's assume you are deploying a legacy JSP page using a JSP container that complies with the JSP 2.0 specifications. In JSP 2.0, EL (Expression Language) constructs will be interpreted by default. However, you are concerned that this may cause problems for your legacy JSP application.Which of the following can be used to configure the JSP container to ignore EL expressions?

·  A) <%@ page isELIgnored="false" %>
·  B) <%@ page isELIgnored="true" %>
·  C) <%@ include isELIgnored="false" %>
·  D) <%@ import isELIgnored="false" %>

Answer
B

Let's assume you have a customerBean which has an address property object. This address object has a city property.

Which of the following is a valid way to set the city property of the customerBean.address object using the appropriate JSTL tags?


·  A) <c:set target="${customerBean.address}" property="city" value = "${city}" />
·  B) <c:set property="customerBean.address" value="${city}" />
·  C) <c:set target="${customerBean}" property="address.city" value = "${city}" />
·  D) <c:set var="${customerBean.address}" property="city" value = "${city}" />

Answer
A

Let's assume you are developing a web application. One of the requirements of this application is to design a flexible framework so that services can be easily added and removed without affecting existing components.

For instance, services such as logging, authentication, debugging, compressing and encoding output, etc.. should be "pluggable" without requiring changes to the core application code. Which of the following design patterns can be used in this situation?


·  A) Intercepting Filter
·  B) Transfer Object
·  C) Business Delegate
·  D) Data Access Object

Answer
A

Let's assume you are writing a JSP page using EL expressions. You have an variable declared as java.util.Map customerMap. You need to retrieve the customer info that is stored in this map.

Which of the following methods is invoked by the JSP engine upon execution of the following EL expression: ${customerMap[CustomerA]}?


·  A) customerMap.get (pageContext.findAttribute ("CustomerA"));

·  B) customerMap.get("CustomerA")
·  C) customerMap.remove ("CustomerA");
·  D) customerMap.getProperty ("CustomerA");
·  E) customerMap.getCustomerA ();

Answer
A

What will be the output of the following JSP page?
 <html><body>
   <% a = 100; %>
   <% int a = 200; %>
   <%! int a = 300; %>
   a = <%= a %>, <%= this.a %>
 </body></html>

A) a = 200, 100
B) a = 300, 100
C) a = 100, 200
D) a = 200, 300
E) The code will not compile as written

Answer
A

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\web.xml       
     E    \doc-root\WEB-INF\classes\web.xml

Answer
C

Which element of the deployment descriptor is used to specify the class of the Servlet. ?  
 
     A    <servlet-class>       
     B    <servlet-name>       
     C    <servlet_name>       
     D    <servlet_class>       
     E    <servlet>
Answer
A

 

SCWCD-9

04/14/2008

0 Comments

 

Which statement best expresses the purpose of a tag library descriptor (TLD) in
an EL function?

a It contains the Java code that will be compiled.
b It invokes the Java method as part of the JSP.
c It matches the tag library with a URI.
d It matches function names to tags that can be used in the JSP.

Answer:
d

Which design pattern allows you to decouple the business logic, data representation,
and data presentation?
(Select one)
a Model-View-Controller
b Transfer Object
c Bimodal Data Access
d Business Delegate
Answer: a

Which of the following is a valid way of getting a bean’s property? (Select one)
a <jsp:useBean action="get" id="address" property="city" />
b <jsp:getProperty id="address" property="city" />
c <jsp:getProperty name="address" property="city" />
d <jsp:getProperty bean="address" property="*" />

Answer:
c

Which of the following web.xml snippets correctly defines the use of a tag
library?
(Select one)
a <taglib>
<uri>http://www.abc.com/sample.tld</uri>
<location>/WEB-INF/sample.tld</location>
</taglib>
b <tag-lib>
<taglib-uri>http://www.abc.com/sample.tld</taglib-uri>
<taglib-location>/WEB-INF/sample.tld</taglib-location>
</tag-lib>
c <taglib>
<taglib-uri>http://www.abc.com/sample.tld</taglib-uri>
<taglib-location>/WEB-INF/sample.tld</taglib-location>
</taglib>
d <tag-lib>
<taglib>http://www.abc.com/sample.tld</taglib-uri>
<taglib>/WEB-INF/sample.tld</taglib-location>
</tag-lib>

Answer:
c

Which object does a SimpleTag tag handler use to access implicit variables?
a PageContext
b BodyContent
c JspContext
d SimpleTagSupport
Answer: c

What is wrong with the following code?
public void doFilter(ServletRequest req, ServletResponse, res,
FilterChain chain)
throws ServletException, IOException {
chain.doFilter(req, res);
HttpServletRequest request = (HttpServletRequest)req;
HttpSession session = request.getSession();
if (session.getAttribute("login") == null) {
session.setAttribute("login"”, new Login());
}
}
a The doFilter() method signature is incorrect; it should take HttpServlet-
Request and HttpServletResponse.
b The doFilter() method should also throw FilterException.
c The call to chain.doFilter(req, res) should be this.doFilter(req, res,
chain).
d Accessing the request after chain.doFilter() results in an IllegalState-
Exception.
e Nothing is wrong with this filter.

Answer:
e

 

SCWCD-8

04/14/2008

0 Comments

 

What is the name of the tag library descriptor element that declares that an
attribute can have a request-time expression as its value?

a [__________________]

Answer:
rtexprvalue

Consider the following HTML page code:
<html><body>
<a href="/servlet/HelloServlet">POST</a>
</body></html>
Which method of HelloServlet will be invoked when the hyperlink displayed
by the above page is clicked?
(Select one)
a doGet
b doPost
c doForm
d doHref
e serviceGet

Answer:
a

Which of the following deployment descriptor snippets correctly associates a servlet
implemented by a class named com.abc.SalesServlet with the name
SalesServlet?
(Select one)
a <servlet>
<servlet-name>com.abc.SalesServlet</servlet-name>
<servlet-class>SalesServlet</servlet-class>
</servlet>
b <servlet>
<servlet-name>SalesServlet</servlet-name>
<servlet-package>com.abc.SalesServlet</servlet-package>
</servlet>
c <servlet>
<servlet-name>SalesServlet</servlet-name>
<servlet-class>com.abc.SalesServlet</servlet-class>
</servlet>
d <servlet name="SalesServlet" class="com.abc.SalesServlet">
<servlet>
<servlet-class name="SalesServlet">
com.abc.SalesServlet
</servlet-class>
</servlet>
e <servlet>
<servlet-name class="com.abc.SalesServlet">
SalesServlet
</servlet-name>
</servlet>

Answer:
c

Consider the contents of the following two JSP files:
File 1: test1.jsp
<html><body>
<% String message = "Hello"; %>
//1 Insert LOC here.
The message is <%= message %>
</body></html>
File 2: test2.jsp
<% message = message + " world!"; %>
Which of the following lines can be inserted at //1 in test1.jsp so that it
prints "The message is Hello world!" when requested?
(Select one)
a <%@ include page="test2.jsp" %>
b <%@ include file="test2.jsp" />
c <jsp:include page="test2.jsp" />
d <jsp:include file="test2.jsp" />

Answer:
b

Which of the following code snippets, when inserted in the doGet() method,
will correctly count the number of GET requests made by a user?
(Select one)
a HttpSession session = request.getSession();
int count = session.getAttribute("count");
session.setAttribute("count", count++);
b HttpSession session = request.getSession();
int count = (int) session.getAttribute("count");
session.setAttribute("count", count++);
c HttpSession session = request.getSession();
int count = ((Integer) session.getAttribute("count")).intValue();
session.setAttribute("count", count++);
d HttpSession session = request.getSession();
int count = ((Integer) session.getAttribute("count")).intValue();
session.setAttribute("count", new Integer(count++));

Answer:
d

What is the term for determining whether a user has access to a particular
resource?
(Select one)
a Authorization
b Authentication
c Confidentiality
d Secrecy

Answer:
a

Which of the following tags can you use to print the value of an expression to the
output stream?
(Select two)
a <%@ %>
b <%! %>
c <% %>
d <%= %>
e <%-- --%>

Answers:
c and d

Which of the following methods will be invoked when a ServletContext is
created?
(Select one)
a contextInstantiated() of javax.servlet.ServletContextListener
b contextInitialized() of javax.servlet.ServletContextListener
c contextInited() of javax.servlet.ServletContextListener
d contextCreated() of javax.servlet.ServletContextListener

Answer:
b

What will be the output of the following code? (Select one)
<html><body>
The value is <%=""%>
</body></html>
a Compilation error
b Runtime error
c The value is
d The value is null

Answer:
c

 

SCWCD-7

04/14/2008

4 Comments

 

Which of the following JSP tags can be used to include the output of another JSP
page into the output of the current page at request time?
(Select one)
a <jsp:insert>
b <jsp:include>
c <jsp:directive.include>
d <jsp:directive:include>
e <%@ include %>

Answer:
b

Which listener will get notified when a context is created?
A ServletContextListener
B ServletConfigListener
C HttpServletContextListener
D ContextListener

Answer:
A
When a context is created, the ServletContextListener will be notified and the method contextInitialized(ServletContextEvent) will be invoked.

Which method correctly set an attribute to context ? Select two
A getServletContext().setAttribute(name, value);
B getServletConfig().setAttribute(name, value);
C getServletConfig().getServletContext().setAttribute(name, value);
D response.setAttribute(name, value);

Answer:


A and C
Answer C is correct because always ServletConfig holds a reference to ServletContext


Which method is used to know when a request is created ?
A RequestListener
B ServletRequestListener
C ServletRequestAttributeListener
D servletListener

Answer:

B
When a request is created the ServletRequestListener will be notified

Consider the following code:
<html><body>
${(5 + 3 + a > 0) ? 1 : 2}
</body></html>
Select the correct statement from the options below:
a It will print 1 because the statement is valid.
b It will print 2 because the statement is valid.
c It will throw an exception because a is undefined.
d It will throw an exception because the expression’s syntax is invalid.

Answer:
a

Which of the following is a valid use of the <jsp:useBean> action? (Select one)
a <jsp:useBean id="address" class="AddressBean" />
b <jsp:useBean name="address" class="AddressBean"/>
c <jsp:useBean bean="address" class="AddressBean" />
d <jsp:useBean beanName="address" class="AddressBean" />

Answer:
a

Which of the following elements are required for a valid <taglib> element in
web.xml? (Select two)
a uri
b taglib-uri
c tagliburi
d tag-uri
e location
f taglib-location
g tag-location
h tagliblocation

Answers:
b and f

Which of the following is not a valid subelement of the <attribute> element in
a TLD? (Select one)
a <name>
b <class>
c <required>
d <type>
Answer:
b

 

SCWCD-6

04/14/2008

10 Comments

 

Which method in the HttpServlet class services the HTTP POST request?
(Select one)
a doPost(ServletRequest, ServletResponse)
b doPOST(ServletRequest, ServletResponse)
c servicePost(HttpServletRequest, HttpServletResponse)
d doPost(HttpServletRequest, HttpServletResponse)
Answer:
d

Which element is used to specify useful information about an initialization
parameter of a servlet in the deployment descriptor?
(Select one)
a param-description
b description
c info
d param-info
e init-param-info

Answer:
b

Which of the following methods will be invoked when a ServletContext is
destroyed?
(Select one)
a contextDestroyed() of javax.servlet.ServletContextListener
b contextDestroyed() of javax.servlet.HttpServletContextListener
c contextDestroyed() of javax.servlet.http.ServletContextListener
d contextDestroyed() of javax.servlet.http.HttpServletContextListener

Answer:
a
Explanation
Remember that the concept of servlet context applies to all the servlets and not
just HttpServlets. Therefore, interfaces related to servlet context belong to the
javax.servlet package.


Which elements are allowed in the element of the deployment
descriptor?
(Select three)
a
b
c
d
e

Answers:
a, c, and d

Explanation
Answer a is correct because you can map filters to named servlets, as well as URL
patterns.

When servlet init parameter will be read ?
A When client makes a request.
B When starting server
C When container initializes the servlet
D When container shuts down.

Answer:
C
When the container initializes the servlet, it reads the DD and creates a parameter list for ServletConfig. These parameters are read only once at the time of initialization only


Which of the following interfaces or classes is used to retrieve the session associated
with a user?
(Select one)
a GenericServlet
b ServletConfig
c ServletContext
d HttpServlet
e HttpServletRequest
f HttpServletResponse

Answer:
e
Explanation
The session associated with a user can only be retrieved using the HttpServlet-
Request.getSession() method.

Which of the following correctly defines data integrity? (Select one)
a It guarantees that information is accessible only to certain users.
b It guarantees that the information is kept in encrypted form on the server.
c It guarantees that unintended parties cannot read the information during transmission
between the client and the server.
d It guarantees that the information is not altered during transmission between the client
and the server.

Answer:
d
Explanation
Answers a and c describe authorization and confidentiality. Encrypting data kept
on the server may be part of some security plans, but is not covered by the servlet
specification.

Which method is used to read the context initialization parameter ? Select two
A getServletConfig().getInitParameter();
B getServletContext().getInitParameter();
C getServletConfig().getContextParameter();
D getServletContext().getServletParameter();
E getServletConfig().getServletContext().getInitParameter();

Answer:
B and E
Option A is incorrect because it reads servlet initialization parameter only, not context initialization parameter. Option c and d are incorrect because , they are invalid methods. Option E is correct because always a ServletConfig contains a reference to the ServletContext.

What getInitParameterNames() of ServletContext does ?
A Returns the init parameters for a servlet
B Returns the init parameter names of a servlet
C Returns the init parameter names of the context
D All of the above.

Answer:
C
getInitParameterNames() returns the names of the context's initialization parameters as an Enumeration

Which is the correct way to set a context initialization parameter ?
A getServletContext().setInitParameter();
B getServletConfig().setInitParameter();
C using DD
D None of the above.

Answer:
C
The only way to set a context initialization parameter is by using tag in the DD only. We cannot set the context param programmatically

Consider the following code and select the correct statement about it from the
options below.
(Select one)
<html><body>
<%! int aNum=5 %>
The value of aNum is <%= aNum %>
</body></html>
a It will print "The value of aNum is 5" to the output.
b It will flag a compile-time error because of an incorrect declaration.
c It will throw a runtime exception while executing the expression.
d It will not flag any compile time or runtime errors and will not print anything to the
output.

Answer:
b

What will be the output of the following code? (Select one)
<html><body>
<% x=3; %>
<% int x=5; %>
<%! int x=7; %>
x = <%=x%>, <%=this.x%>
</body></html>
a x = 3, 5
b x = 3, 7
c x = 5, 3
d x = 5, 7
e Compilation error

Answer:
c

 

SCWCD-5

04/14/2008

0 Comments

 

What will be the output , when accessing the following servlet

import javax.servlet.http.*;

public class TestServlet extends HttpServlet {

}

A Blank Screen
B Runtime Error
C Compiler Error
D HTTP 405, error message.
D HTTP 404, error message.

Answer

D
HttpServlet is providing a default implementation for Http Methods, it will not give any compile time or run time error. But the default implementation will give an HTTP 405 error message (At least in BEA Web logic server).


What is the return type of request.getParameterValues()?

A String
B Vector
C String[]
D ArrayList

Answer

C
getParameterValues() returns an array o f String objects containing all of the values the given request parameter has, or null if the parameter does not exist

Which method is used to get the HTTP method of the request?

A request.getMethod();
B request.getForm()
C request.getHttpMethod()
D request.getFormMethod()

Answer

A
Return the name of the HTTP method with which the servlet request was made , such as GET, POST etc..


In order to redirect a servlet , what is the method used ?

A response.sendRedirect(java.net.URL)
B response.sendRedirect(String)
C response.sendURL(java.net.URL)
D response.sendURL(String)

Answer

B
response.sendRedirect(String) is used for redirecting response to another URL.


Which method is used for finding out what the server is receiving ?

A GET
B POST
C PUT
D TRACE

Answer

D
TRACE gives information about what the server is receiving . Used mainly for debugging only.

Which methods are used to set a header? Choose all that apply.

A response.setHeader()
B response.addHeader()
C response.addStringHeader()
D response.setDateHeader()
E response.addDateHeader()

Answer

A, B, D and E
setHeader and addHeader adds a header value. But setHeader overwrites existing value if one exist where as addHeader adds one more value for this header. The setDateHeader and addDateHeader are used fro setting date headers.

What will be the output of the following expression ?
<%= System.out.println("Hello.."); %>

A Hello..
B System.out.println("Hello..")
C Compiler Error
D java.io.PrintStream@1ccf82Hello

Answer

C
We cannot use 'void' in JSP expression. All JSP expression should return a valid type except void.


Which method is used to log messages from a servlet ?

A getServletConfig().log();
B getServletContext().log();
C getServletConfig().log(String)
D getServletContext().log(String)

Answer

B and D
The log() method is defined in ServletContext interface.


What are the mandatory sub elements of <login-config> element ?

A <auth-method>
B <form-login-config>
C <login>
D No mandatory sub element.

Answer

D
The <login-config> element does not define any mandatory sub element.

What methods are used to get the header information from the client ? Select all that apply.

A request.getHeader(String)
B request.getFormHeader(String)
C request.getIntHeader(String)
D request.getDateHeader(String)

Answer

A, C and D
(String headername) is used to get the header from the client. The getDateHeader is used for getting date headers. It will throw an IllegalArgumentException , if the header cannot be converted to a date. getIntHeader will return the value of specified header as an int. if the specified header cannot be converted to an int , it till throw a NumberFormatException.

 
    SCWCD Sets


    Archives

    May 2008
    April 2008