Saturday 17 December 2011

SCWCD Questions 261 - 276


QUESTION NO: 261


Which three are true about servlet filters? (Choose three.)
A. A filter must implement the destroy method.
B. A filter must implement the doFilter method.
C. A servlet may have multiple filters associated with it.
D. A servlet that is to have a filter applied to it must implement the javax.servlet.FilterChain
interface.
E. A filter that is part of a filter chain passes control to the next filter in the chain by invoking the
FilterChain.forward method.
F. For each <filter> element in the web application deployment descriptor, multiple instances of a
filter may be created by the web container.

Answer: A,B,C


QUESTION NO: 262 DRAG DROP


Click the Task button.
Place the XML elements in the web application deployment descriptor solution to configure a
servlet context event listener named com.example.MyListener.
Answer:


Explanation:


QUESTION NO: 263

Which is true about the web container request processing model?
A. The init method on a filter is called the first time a servlet mapped to that filter is invoked.
B. A filter defined for a servlet must always forward control to the next resource in the filter chain.
C. Filters associated with a named servlet are applied in the order they appear in the web
application deployment descriptor file.
D. If the init method on a filter throws an UnavailableException, then the container will make no
further attempt to execute it.

Answer: C

QUESTION NO: 264

Your IT department is building a lightweight Front Controller servlet that invokes an application
logic object with the interface:
public interface ApplicationController {
public String invoke(HttpServletRequest request)
}
The return value of this method indicates a symbolic name of the next view. From this name, the
Front Controller servlet looks up the JSP URL in a configuration table. This URL might be an
absolute path or a path relative to the current request. Next, the Front Controller servlet must send
the request to this JSP to generate the view. Assume that the servlet variable request is assigned
the current HttpServletRequest object and the variable context is assigned the webapp's
ServletContext.
Which code snippet of the Front Controller servlet accomplishes this goal?
A. Dispatcher view
= context.getDispatcher(viewURL);
view.forwardRequest(request, response);
B. Dispatcher view
= request.getDispatcher(viewURL);
view.forwardRequest(request, response);
C. RequestDispatcher view
= context.getRequestDispatcher(viewURL);
view.forward(request, response);
D. RequestDispatcher view
= request.getRequestDispatcher(viewURL);
view.forward(request, response);

Answer: D

QUESTION NO: 265

Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the
ServletA.service method:
20. String key = "com.example.data";
21. session.setAttribute(key, "Hello");
22. Object value = session.getAttribute(key);
23.
Assume session is an HttpSession, and is not referenced anywhere else in ServletA.
Which two changes, taken together, ensure that value is equal to "Hello" on line 23? (Choose
two.)
A. ensure that the ServletB.service method is synchronized
B. ensure that the ServletA.service method is synchronized
C. ensure that ServletB synchronizes on the session object when setting session attributes
D. enclose lines 21-22 in a synchronized block:
synchronized(this) {
session.setAttribute(key, "Hello");
value = session.getAttribute(key);
}
E. enclose lines 21-22 in a synchronized block:
synchronized(session) {
session.setAttribute(key, "Hello");
value = session.getAttribute(key);
}

Answer: C,E

QUESTION NO: 266

Which retrieves all cookies sent in a given HttpServletRequest request?
A. request.getCookies()
B. request.getAttributes()
C. request.getSession().getCookies()
D. request.getSession().getAttributes()

Answer: A

QUESTION NO: 267

Your company has a corporate policy that prohibits storing a customer's credit card number in any
corporate database. However, users have complained that they do NOT want to re-enter their
credit card number for each transaction. Your management has decided to use client-side cookies
to record the user's credit card number for 120 days. Furthermore, they also want to protect this
information during transit from the web browser to the web container; so the cookie must only be
transmitted over HTTPS. Which code snippet creates the "creditCard" cookie and adds it to the
out going response to be stored on the user's web browser?
A. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setAge(10368000);
13. response.addCookie(c);
B. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setHttps(true);
12. c.setMaxAge(10368000);
13. response.setCookie(c);
C. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setMaxAge(10368000);
13. response.addCookie(c);
D. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setHttps(true);
12. c.setAge(10368000);
13. response.addCookie(c);
E. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setAge(10368000);
13. response.setCookie(c);

Answer: C

QUESTION NO: 268 DRAG DROP

Click the Task button.
Given a servlet mapped to /control, place the correct URI segment returned as a String on the
corresponding HttpServletRequest method call for the URI: /myapp/control/processorder.


Answer:


QUESTION NO: 269

A web browser need NOT always perform a complete request for a particular page that it suspects
might NOT have changed. The HTTP specification provides a mechanism for the browser to
retrieve only a partial response from the web server; this response includes information, such as
the Last-Modified date but NOT the body of the page. Which HTTP method will the browser use to
retrieve such a partial response?
A. GET
B. ASK
C. SEND
D. HEAD
E. TRACE
F. OPTIONS

Answer: D

QUESTION NO: 270

You are creating a servlet that generates stock market graphs. You want to provide the web
browser with precise information about the amount of data being sent in the response stream.
Which two HttpServletResponse methods will you use to provide this information? (Choose two.)
A. response.setLength(numberOfBytes);
B. response.setContentLength(numberOfBytes);
C. response.setHeader("Length", numberOfBytes);
D. response.setIntHeader("Length", numberOfBytes);
E. response.setHeader("Content-Length", numberOfBytes);
F. response.setIntHeader("Content-Length", numberOfBytes);

Answer: B,F

QUESTION NO: 271

Which two prevent a servlet from handling requests? (Choose two.)
A. The servlet's init method returns a non-zero status.
B. The servlet's init method throws a ServletException.
C. The servlet's init method sets the ServletResponse's content length to 0.
D. The servlet's init method sets the ServletResponse's content type to null.
E. The servlet's init method does NOT return within a time period defined by the servlet container.

Answer: B,E

QUESTION NO: 272

A web application allows the HTML title banner to be set using a servlet context initialization
parameter called titleStr. Which two properly set the title in this scenario? (Choose two.)
A. <title>${titleStr}</title>
B. <title>${initParam.titleStr}</title>
C. <title>${params[0].titleStr}</title>
D. <title>${paramValues.titleStr}</title>
E. <title>${initParam['titleStr']}</title>
F. <title>${servletParams.titleStr}</title>
G. <title>${request.get("titleStr")}</title>

Answer: B,E

QUESTION NO: 273

You are building a dating service web site. Part of the form to submit a client's profile is a group of
radio buttons for the person's hobbies:
20. <input type='radio' name='hobbyEnum' value='HIKING'>Hiking <br>
21. <input type='radio' name='hobbyEnum' value='SKIING'>Skiing <br>
22. <input type='radio' name='hobbyEnum' value='SCUBA'>SCUBA Diving
23. <!-- and more options -->
After the user submits this form, a confirmation screen is displayed with these hobbies listed.
Assume that an application-scoped variable, hobbies, holds a map between the Hobby
enumerated type and the display name.
Which EL code snippet will display Nth element of the user's selected hobbies?
A. ${hobbies[hobbyEnum[N]}
B. ${hobbies[paramValues.hobbyEnum[N]]}
C. ${hobbies[paramValues@'hobbyEnum'@N]}
D. ${hobbies.get(paramValues.hobbyEnum[N])}
E. ${hobbies[paramValues.hobbyEnum.get(N)]}

Answer: B

QUESTION NO: 274

Given a web application in which the request parameter productID contains a product identifier.
Which two EL expressions evaluate the value of the productID? (Choose two.)
A. ${productID}
B. ${param.productID}
C. ${params.productID}
D. ${params.productID[1]}
E. ${paramValues.productID}
F. ${paramValues.productID[0]}
G. ${pageContext.request.productID}

Answer: B,F

QUESTION NO: 275

You are building a web application with a scheduling component. On the JSP, you need to show
the current date, the date of the previous week, and the date of the next week. To help you
present this information, you have created the following EL functions in the 'd' namespace:
name: curDate; signature: java.util.Date currentDate()
name: addWeek; signature: java.util.Date addWeek(java.util.Date, int)
name: dateString; signature: java.util.String getDateString(java.util.Date)
Which EL code snippet will generate the string for the previous week?
A. ${d:dateString(addWeek(curDate(), -1))}
B. ${d:dateString[addWeek[curDate[], -1]]}
C. ${d:dateString[d:addWeek[d:curDate[], -1]]}
D. ${d:dateString(d:addWeek(d:curDate(), -1))}

Answer: D

QUESTION NO: 276

You are building a dating web site. The client's date of birth is collected along with lots of other
information. The Person class has a derived method, getAge():int, which returns the person's age
calculated from the date of birth and today's date. In one of your JSPs you need to print a special
message to clients within the age group of 25 through 35. Which two EL code snippets will return
true for this condition? (Choose two.)
A. ${client.age in [25,35]}
B. ${client.age between [25,35]}
C. ${client.age between 25 and 35}
D. ${client.age <= 35 && client.age >= 25}
E. ${client.age le 35 and client.age ge 25}
F. ${not client.age > 35 && client.age < 25}

Answer: D,E


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...