Monday, January 5, 2015

SCWCD Questions And Answers Part 4

Q: 91 Assume the custom tag my:errorProne always throws a java.lang.RuntimeException with the message "File not found."
An error page has been configured for this JSP page.

Which option prevents the exception thrown by my:errorProne from invoking the error page mechanism, and outputs the message "File not found" in the response?

A. <c:try catch="ex"> <my:errorProne /> </c:try> ${ex.message} 
B. <c:catch var="ex"> <my:errorProne /> </c:catch> ${ex.message}
C. <c:try> <my:errorProne /> </c:try> <c:catch var="ex" /> ${ex.message}
D. <c:try> <my:errorProne /> <c:catch var="ex" /> ${ex.message} </c:try>
E. <my:errorProne> <c:catch var="ex"> ${ex.message} </c:catch> </my:errorProne>

Answer: B


Q: 92 A JSP page contains a taglib directive whose uri attribute has the value dbtags. Which XML element within the web application deployment descriptor defines the associated TLD?

A. <tld> <uri>dbtags</uri> <location>/WEB-INF/tlds/dbtags.tld</location> </tld>
B. <taglib> <uri>dbtags</uri> <location>/WEB-INF/tlds/dbtags.tld</location> </taglib>
C. <tld> <tld-uri>dbtags</tld-uri>
<tld-location>/WEB-INF/tlds/dbtags.tld</tld-location> </tld>
D. <taglib> <taglib-uri>dbtags</taglib-uri> <taglib-location> /WEB-INF/tlds/dbtags.tld </taglib-location></taglib>

Answer: D


Q: 93 Assume that a news tag library contains the tags lookup and item:
lookup Retrieves the latest news headlines and executes the tag body once for each headline. Exposes a NESTED page-scoped attribute called headline of type com.example.Headline containing details for that headline.
item Outputs the HTML for a single news headline. Accepts an attribute info of type com.example.Headline containing details for the headline to be rendered.Which snippet of JSP code returns the latest news headlines in an HTML table, one per row?


A.<table> <tr> <td> <news:lookup />
<news:item info="${headline}" /> </td>
</tr>
</table>
B.<news:lookup />
<table>
<tr>
<td><news:item info="${headline}" /></td> </tr>
</table>
C.<table>
<news:lookup>
<tr>
<td><news:item info="${headline}" /></td> </tr>
</news:lookup>
</table>
D.<table>
<tr>
<news:lookup>
<td><news:item info="${headline}" /></td>
</news:lookup>
</tr>
</table>

Answer: C


Q: 94 Click the Exhibit button.

Assuming the tag library in the exhibit is imported with the prefix stock, which custom tag invocation outputs the contents of the variable exposed by the quote tag?


A. <stock:quote symbol="SUNW" /> ${var}
B. ${var}
<stock:quote symbol="SUNW" />
C.<stock:quote symbol="SUNW"> ${var}
</stock:quote>
D. <stock:quote symbol="SUNW" var="quote" />
${quote}
E. <stock:quote symbol="SUNW" var="quote"> <%= quote %>
</stock:quote>

Answer: D


Q: 95 Which two are true about the JSTL core iteration custom tags? (Choose two.)

A. It may iterate over arrays, collections, maps, and strings.
B. The body of the tag may contain EL code, but not scripting code.
C. When looping over collections, a loop status object may be used in the tag body.
D. It may iterate over a map, but only the key of the mapping may be used in the tag body.
E. When looping over integers (for example begin='1' end='10'), a loop status object may not be used in the tag body.

Answer: A, C


Q: 96 Assume a JavaBean com.example.GradedTestBean exists and has two attributes. The attribute name is of type java.lang.String and the attribute score is of type java.lang.Integer.
An array of com.example.GradedTestBean objects is exposed to the page in a request-scoped attribute called results. Additionally, an empty java.util.HashMap called resultMap is placed in the page scope.

A JSP page needs to add the first entry in results to resultMap, storing the name attribute of the bean as the key and the score attribute of the bean as the value.

Which code snippet of JSTL code satisfies this requirement?

A. ${resultMap[results[0].name] = results[0].score}
B. <c:set var="${resultMap}" key="${results[0].name}" value="${results[0].score}" />
C. <c:set var="resultMap" property="${results[0].name}"> ${results[0].value}
</c:set>
D. <c:set var="resultMap" property="${results[0].name}" value="${results[0].score}" />
E. <c:set target="${resultMap}" property="${results[0].name}" value="${results[0].score}" />

Answer: E


Q: 97 You are creating a JSP page to display a collection of data. This data can be displayed in several different ways so the architect on your project decided to create a generic servlet that generates a comma-delimited string so that various pages can render the data in different ways. This servlet takes on request parameter: objectID. Assume that this servlet is mapped to the URL pattern: /WEB-INF/data.

In the JSP you are creating, you need to split this string into its elements separated by commas and generate an HTML <ul> list from the data.

Which JSTL code snippet will accomplish this goal?

A. <c:import varReader='dataString' url='/WEB-INF/data'> <c:param name='objectID' value='${currentOID}' /> </c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'> <li>${item}</li>
</c:forTokens>
</ul>
B. <c:import varReader='dataString' url='/WEB-INF/data'> <c:param name='objectID' value='${currentOID}' /> </c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'> <li>${item}</li>
</c:forTokens>
</ul>
C. <c:import var='dataString' url='/WEB-INF/data'> <c:param name='objectID' value='${currentOID}' /> </c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'> <li>${item}</li>
</c:forTokens>
</ul>
D. <c:import var='dataString' url='/WEB-INF/data'> <c:param name='objectID' value='${currentOID}' /> </c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'> <li>${item}</li>
</c:forTokens>
</ul>

Answer: D


Q: 98 A web application contains a tag file called beta.tag in /WEB-INF/tags/alpha. A JSP page called sort.jsp exists in the web application and contains only this JSP code:

1. <%@ taglib prefix="x"
2. tagdir="/WEB-INF/tags/alpha" %>
3. <x:beta />

The sort.jsp page is requested.


Which two are true? (Choose two.)

A. Tag files can only be accessed using a tagdir attribute.
B. The sort.jsp page translates successfully and invokes the tag defined by beta.tag.
C. The sort.jsp page produces a translation error because a taglib directive must always have a uri attribute.
D. Tag files can only be placed in /WEB-INF/tags, and NOT in any subdirectories of /WEB-INF/tags.
E. The tagdir attribute in line 2 can be replaced by a uri attribute if a TLD referring to beta.tag is created and added to the web application.
F. The sort.jsp page produces a translation error because the tagdir attribute on lines 1-2 specifies a directory other than /WEB-INF/tags, which is illegal.

Answer: B, E


Q: 99 What is the purpose of session management?

A. To manage the user's login and logout activities.
B. To store information on the client-side between HTTP requests.
C. To store information on the server-side between HTTP requests.
D. To tell the web container to keep the HTTP connection alive so it can make subsequent requests without the delay of making the TCP connection.

Answer: C


Q: 100 The Squeaky Beans Inc. shopping application was initially developed for a non-distributed environment. The company recently purchased the Acme Application Server, which supports distributed HttpSession objects. When deploying the application to the server, the deployer marks it as distributable in the web application deployment descriptor to take advantage of this feature.

Given this scenario, which two must be true? (Choose two.)

A. The J2EE web container must support migration of objects that implement Serializable.
B. The J2EE web container must use the native JVM Serialization mechanism for distributing HttpSession objects.
C. As per the specification, the J2EE web container ensures that distributed HttpSession objects will be stored in a database.
D. Storing references to Enterprise JavaBeans components in the HttpSession object might NOT be supported by J2EE web containers.

Answer: A, D



Q: 101 In your web application, you need to execute a block of code whenever the session object is first created. Which design will accomplish this goal? 

A. Create an HttpSessionListener class and implement the sessionInitialized method with that block of code.
B. Create an HttpSessionActivationListener class and implement the sessionCreated method with that block of code.
C. Create a Filter class, call the getSession(false) method, and if the result was null, then execute that block of code.
D. Create an HttpSessionListener class and implement the sessionCreated method with that block of code.
E. Create a Filter class, call the getSession(true) method, and if the result was NOT null, then execute that block of code.

Answer: D


Q: 102 Which interface must a class implement so that instances of the class are notified after any object is added to a session?

A. javax.servlet.http.HttpSessionListener
B. javax.servlet.http.HttpSessionValueListener
C. javax.servlet.http.HttpSessionBindingListener
D. javax.servlet.http.HttpSessionAttributeListener

Answer: D


Q: 103 Which method must be used to encode a URL passed as an argument to HttpServletResponse.sendRedirect when using URL rewriting for session tracking?

A. ServletResponse.encodeURL
B. HttpServletResponse.encodeURL
C. ServletResponse.encodeRedirectURL
D. HttpServletResponse.encodeRedirectURL 

Answer: D


Q: 104 Users of your web application have requested that they should be able to set the duration of their sessions. So for example, one user might want a webapp to stay connected for an hour rather than the webapp's default of fifteen minutes; another user might want to stay connected for a whole day.

Furthermore, you have a special login servlet that performs user authentication and retrieves the User object from the database. You want to augment this code to set up the user's specified session duration.

Which code snippet in the login servlet will accomplish this goal?

 A. User user = // retrieve the User object from the database session.setDurationInterval(user.getSessionDuration()); 
B. User user = // retrieve the User object from the database session.setMaxDuration(user.getSessionDuration());
C. User user = // retrieve the User object from the database session.setInactiveInterval(user.getSessionDuration());
D. User user = // retrieve the User object from the database session.setDuration(user.getSessionDuration());
E. User user = // retrieve the User object from the database session.setMaxInactiveInterval(user.getSessionDuration());
F. User user = // retrieve the User object from the database session.setMaxDurationInterval(user.getSessionDuration());

Answer: E


Q: 105 Which two classes or interfaces provide a getSession method? (Choose two.)

A. javax.servlet.http.HttpServletRequest
B. j avax.servlet.http.HttpSessionContext
C. javax.servlet.http.HttpServletResponse
D. javax.servlet.http.HttpSessionBindingEvent
E. javax.servlet.http.HttpSessionAttributeEvent 

Answer: A, D



Q: 106 Given the security constraint in a DD:

101.  <security-constraint>
102.      <web-resource-collection>
103.          <web-resource-name>Foo</web-resource-name>
104.          <url-pattern>/Bar/Baz/*</url-pattern>
105.          <http-method>POST</http-method>
106.      </web-resource-collection>
107.      <auth-constraint>
108.          <role-name>DEVELOPER</role-name>
109.      </auth-constraint>
110.  </security-constraint>

And given that "MANAGER" is a valid role-name, which four are true for this security constraint? (Choose four.)

A. MANAGER can do a GET on resources in the /Bar/Baz directory. 
B. MANAGER can do a POST on any resource in the /Bar/Baz directory.
C. MANAGER can do a TRACE on any resource in the /Bar/Baz directory.
D. DEVELOPER can do a GET on resources in the /Bar/Baz directory.
E. DEVELOPER can do only a POST on resources in the /Bar/Baz directory.
F. DEVELOPER can do a TRACE on any resource in the /Bar/Baz directory. 

Answer: A, C, D, F


Q: 107 Which activity supports the data integrity requirements of an application?

A. using HTTPS as a protocol 
B. using an LDAP security realm
C. using HTTP Basic authentication
D. using forms-based authentication

Answer: A 


Q: 108 Which mechanism requires the client to provide its public key certificate?

A. HTTP Basic Authentication
B. Form Based Authentication
C. HTTP Digest Authentication
D. HTTPS Client Authentication

Answer: D


Q: 109 Given the two security constraints in a deployment descriptor:

101.  <security-constraint>
102.      <!--a correct url-pattern and http-method goes here-->
103.      <auth-constraint><role-name>SALES</role-name></auth-
103.      <auth-constraint>
104.          <role-name>SALES</role-name>
105.      </auth-constraint>
106.  </security-constraint>
107.  <security-constraint>
108.      <!--a correct url-pattern and http-method goes here-->
109.      <!-- Insert an auth-constraint here -->
110.  </security-constraint>

If the two security constraints have the same url-pattern and http-method, which two, inserted independently at line 109, will allow users with role names of either SALES or MARKETING to access this resource? (Choose two.)

A. <auth-constraint/> 
B. <auth-constraint> <role-name>*</role-name> </auth-constraint>
C. <auth-constraint>
<role-name>ANY</role-name> </auth-constraint>
D. <auth-constraint> <role-name>MARKETING</role-name> </auth-constraint>

Answer: B, D


Q: 110 Given this fragment in a servlet:

23. if(req.isUserInRole("Admin")) {
24. // do stuff
25. }

And the following fragment from the related Java EE deployment descriptor:

812.        <security-role-ref>
813.            <role-name>Admin</role-name>
814.            <role-link>Administrator</role-link>
815.        </security-role-ref>
900.        <security-role> 
901.            <role-name>Admin</role-name>
902.            <role-name>Administrator</role-name>
903.        </security-role>

What is the result?

A. Line 24 can never be reached.
B. The deployment descriptor is NOT valid.
C. If line 24 executes, the user's role will be Admin.
D. If line 24 executes, the user's role will be Administrator.
E. If line 24 executes the user's role will NOT be predictable.

Answer: D


Q: 111 Which two are true about authentication? (Choose two.)

A. Form-based logins should NOT be used with HTTPS. 
B. When using Basic Authentication the target server is NOT authenticated.
C. J2EE compliant web containers are NOT required to support the HTTPS protocol.
D. Web containers are required to support unauthenticated access to unprotected web resources.
E. Form-based logins should NOT be used when sessions are maintained by cookies or SSL session information.

Answer: B, D


Q: 112 Given:

11.  <%
12.      request.setAttribute("vals", new String[]{"1","2","3","4"});
13.      request.setAttribute("index", "2"); 
14.  %>
15.  <%-- insert code here --%>

Which three EL expressions, inserted at line 15, are valid and evaluate to "3"? (Choose three.)

A. ${vals.2} 
B. ${vals["2"]}
C. ${vals.index}
D. ${vals[index]}
E. ${vals}[index]
F. ${vals.(vals.index)}
G. ${vals[vals[index-1]]}

Answer: B, D, G


Q: 113 Given:

11. <% java.util.Map map = new java.util.HashMap();
12. request.setAttribute("map", map);
13. map.put("a", "true");
14. map.put("b", "false");
15. map.put("c", "42"); %>


Which three EL expressions are valid and evaluate to true? (Choose three.)

A. ${not map.c}
B. ${map.d or map.a}
C. ${map.a and map.d}
D. ${map.false or map.true}
E. ${map.a and map.b or map.a}
F. ${map['true'] or map['false']}

Answer: A, B, E


Q: 114 Given:
  
   http://com.example/myServlet.jsp?num=one&num=two&num=three

Which two produce the output "one, two and three"? (Choose two.)

A. ${param.num[0],[1] and [2]}
B. ${paramValues[0],[1] and [2]}
C. ${param.num[0]}, ${param.num[1]} and ${param.num[2]}
D. ${paramValues.num[0]}, ${paramValues.num[1]} and ${paramValues.num[2]}
E. ${paramValues["num"][0]}, ${paramValues["num"][1]} and ${paramValues["num"][2]}
F. ${parameterValues.num[0]}, ${parameterValues.num[1]} and ${parameterValues.num[2]}
G. ${parameterValues["num"]["0"]}, ${parameterValues["num"]["1"]} and ${parameterValues["num"]["2"]}

Answer: D, E


Q: 115 Given a web application in which the cookie userName is expected to contain the name of the user. Which EL expression evaluates to that user name?

A. ${userName}
B. ${cookie.userName}
C. ${cookie.user.name}
D. ${cookies.userName[0]}
E. ${cookies.userName}[1]
F. ${cookies.get('userName')}

Answer: B


Q: 116 Given an EL function declared with:

11.  <function>
12.      <name>spin</name>
13.      <function-class>com.example.Spinner</function-class>
14.      <function-signature>
15.          java.lang.String spinIt()
16.      </function-signature>
17.  </function>

Which two are true? (Choose two.)

A. The function method must have the signature: public String spin(). 
B. The method must be mapped to the logical name "spin" in the web.xml file.
C. The function method must have the signature:
public String spinIt().
D. The function method must have the signature public static String spin().
E. The function method must have the signature: public static String spinIt().
F. The function class must be named Spinner, and must be in the package com.example.

Answer: E, F


Q: 117 Given a JSP page:

11.  <n:recurse>
12.      <n:recurse>
13.          <n:recurse>
14.              <n:recurse />
15.          </n:recurse>
16.      </n:recurse>
17.  </n:recurse>

The tag handler for n:recurse extends SimpleTagSupport.

Assuming an n:recurse tag can either contain an empty body or another n:recurse tag, which strategy allows the tag handler for n:recurse to output the nesting depth of the deepest n:recurse tag?

A. It is impossible to determine the deepest nesting depth because it is impossible for tag handlers that extend SimpleTagSupport to communicate with their parent and child tags.
B. Create a private non-static attribute in the tag handler class called count of type int initialized to 0. Increment count in the doTag method. If the tag has a body, invoke the fragment for that body. Otherwise, output the value of count.
C. Start a counter at 1. Call getChildTags(). If it returns null, output the value of the counter. Otherwise, increment counter and continue from where getChildTags() is called. Skip processing of the body.
D. If the tag has a body, invoke the fragment for that body.Otherwise, start a counter at 1. Call getParent(). If it returns null, output the value of the counter Otherwise, increment the counter and continue from where getParent() is called.

Answer: D


Q: 118 Click the Exhibit button.

The h:highlight tag renders its body, highlighting an arbitrary number of words, each of which is passed as an attribute (word1, word2, ...). For example, a JSP page can invoke the h:highlight tag as follows:

11.  <h:highlight color="yellow" word1="high" word2="low">
12.      high medium low
13.  </h:highlight> 

Given that HighlightTag extends SimpleTagSupport, which three steps are necessary to implement the tag handler for the highlight tag? (Choose three).



A. add a doTag method
B. add a doStartTag method
C. add a getter and setter for the color attribute
D. create and implement a TagExtraInfo class
E. implement the DynamicAttributes interface
F. add a getter and setter for the word1 and word2 attributes

Answer: A, C, E


Q: 119 Given:

5.  public class MyTagHandler extends TagSupport {

6.      public int doStartTag() throws JspException {
7.          try {
8.              // insert code here
9.          } catch(Exception ex) { /* handle exception */ }
10.          return super.doStartTag();
11.      }
...
42. }

Which code snippet, inserted at line 8, causes the value foo to be output?

A. JspWriter w = pageContext.getOut(); w.print("foo");
B. JspWriter w = pageContext.getWriter(); w.print("foo");
C. JspWriter w = new JspWriter(pageContext.getWriter()); w.print("foo");
D. JspWriter w = new JspWriter(pageContext.getResponse()); w.print("foo");

Answer: A


Q: 120 Given:

6.  <myTag:foo bar='42'>

7.      <%="processing" %>
8.  </myTag:foo>

and a custom tag handler for foo which extends TagSupport.

Which two are true about the tag handler referenced by foo? (Choose two.)

A. The doStartTag method is called once.
B. The doAfterBody method is NOT called.
C. The EVAL_PAGE constant is a valid return value for the doEndTag method.
D. The SKIP_PAGE constant is a valid return value for the doStartTag method.
E. The EVAL_BODY_BUFFERED constant is a valid return value for the doStartTag method.

Answer: A, C

No comments :

Post a Comment