Saturday, 17 December 2011

SCWCD Questions 151 - 160


QUESTION NO: 151 DRAG DROP



Click the Task button.
Place the code snippets in the proper order to construct the JSP code to include dynamic content
into a JSP page at request-time.



Answer:


Explanation:

QUESTION NO: 152

Given:
6. <% int[] nums = {42, 420, 4200};
7. request.setAttribute("foo", nums); %>
Which two successfully translate and result in a value of true? (Choose two.)
A. ${true or false}
B. ${requestScope[foo][0] > 500}
C. ${requestScope['foo'][1] = 420}
D. ${(requestScope['foo'][0] lt 50) && (3 gt 2)}

Answer: A,D

QUESTION NO: 153

Click the Exhibit button.
Given:
11. <% com.example.Advisor advisor = new com.example.Advisor(); %>
12. <% request.setAttribute("foo", advisor); %>
Assuming there are no other "foo" attributes in the web application, which three are valid EL
expressions for retrieving the advice property of advisor? (Choose three.)

A. ${foo.advice}
B. ${request.foo.advice}
C. ${requestScope.foo.advice}
D. ${requestScope[foo[advice]]}
E. ${requestScope["foo"]["advice"]}
F. ${requestScope["foo"["advice"]]}

Answer: A,C,E

QUESTION NO: 154

You are creating an error page that provides a user-friendly screen whenever a server exception
occurs. You want to hide the stack trace, but you do want to provide the exception's error
message to the user so the user can provide it to the customer service agent at your company.
Which EL code snippet inserts this error message into the error page?
A. Message: <b>${exception.message}</b>
B. Message: <b>${exception.errorMessage}</b>
C. Message: <b>${request.exception.message}</b>
D. Message: <b>${pageContext.exception.message}</b>
E. Message: <b>${request.exception.errorMessage}</b>
F. Message: <b>${pageContext.exception.errorMessage}</b>

Answer: D

QUESTION NO: 155

You are building a dating web site. The client's date of birth is collected along with lots of other
information. You have created an EL function with the signature: calcAge(java.util.Date):int and it
is assigned to the name, age, in the namespace, funct. In one of your JSPs you need to print a
special message to clients who are younger than 25. Which EL code snippet will return true for
this condition?
A. ${calcAge(client.birthDate) < 25}
B. ${calcAge[client.birthDate] < 25}
C. ${funct:age(client.birthDate) < 25}
D. ${funct:age[client.birthDate] < 25}
E. ${funct:calcAge(client.birthDate) < 25}
F. ${funct:calcAge[client.birthDate] < 25}

Answer: C

QUESTION NO: 156

Given:
11. <% java.util.Map map = new java.util.HashMap();
12. request.setAttribute("map", map);
13. map.put("a", "b");
14. map.put("b", "c");
15. map.put("c", "d"); %>
16. <%-- insert code here --%>
Which three EL expressions, inserted at line 16, are valid and evaluate to "d"? (Choose three.)
A. ${map.c}
B. ${map[c]}
C. ${map["c"]}
D. ${map.map.b}
E. ${map[map.b]}
F. ${map.(map.b)}

Answer: A,C,E

QUESTION NO: 157

Assume the tag handler for a st:simple tag extends SimpleTagSupport. In what way can scriptlet
code be used in the body of st:simple?
A. set the body content type to JSP in the TLD
B. Scriptlet code is NOT legal in the body of st:simple.
C. add scripting-enabled="true" to the start tag for the st:simple element
D. add a pass-through Classic tag with a body content type of JSP to the body of st:simple, and
place the scriptlet code in the body of that tag

Answer: B

QUESTION NO: 158

Which statement is true if the doStartTag method returns EVAL_BODY_BUFFERED ?
A. The tag handler must implement BodyTag.
B. The doAfterBody method is NOT called.
C. The setBodyContent method is called once.
D. It is never legal to return EVAL_BODY_BUFFERED from doStartTag.

Answer: C

QUESTION NO: 159

You are creating a library of custom tags that mimic the HTML form tags. When the user submits a
form that fails validation, the JSP form is forwarded back to the user. The <t:textField> tag must
support the ability to re-populate the form field with the request parameters from the user's last
request. For example, if the user entered "Samantha" in the text field called firstName, then the
form is re-populated like this:
<input type='text' name='firstName' value='Samantha' />
Which tag handler method will accomplish this goal?
A. public int doStartTag() throws JspException {
JspContext ctx = getJspContext();
String value = ctx.getParameter(this.name);
if ( value == null ) value = "";
JspWriter out = pageContext.getOut();
try {
out.write(String.format(INPUT, this.name, value));
} (Exception e) { throw new JspException(e); }
return SKIP_BODY;
}
private static String INPUT
= "<input type='text' name='%s' value='%s' />";
B. public void doTag() throws JspException {
JspContext ctx = getJspContext();
String value = ctx.getParameter(this.name);
if ( value == null ) value = "";
JspWriter out = pageContext.getOut();
try {
out.write(String.format(INPUT, this.name, value));
} (Exception e) { throw new JspException(e); }
}
private static String INPUT
= "<input type='text' name='%s' value='%s' />";
C. public int doStartTag() throws JspException {
ServletRequet request = pageContext.getRequest();
String value = request.getParameter(this.name);
if ( value == null ) value = "";
JspWriter out = pageContext.getOut();
try {
out.write(String.format(INPUT, this.name, value));
} (Exception e) { throw new JspException(e); }
return SKIP_BODY;
}
private static String INPUT
= "<input type='text' name='%s' value='%s' />";
D. public void doTag() throws JspException {
ServletRequet request = pageContext.getRequest();
String value = request.getParameter(this.name);
if ( value == null ) value = "";
JspWriter out = pageContext.getOut();
try {
out.write(String.format(INPUT, this.name, value));
} (Exception e) { throw new JspException(e); }
}
private static String INPUT
= "<input type='text' name='%s' value='%s' />";

Answer: C

QUESTION NO: 160

Which two directives are applicable only to tag files? (Choose two.)
A. tag
B. page
C. taglib
D. include
E. variable

Answer: A,E






No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...