SCWCD : Expression Language


Q.1
You need to create a JSP that generates some JavaScript code to populate an array of strings used on the client-side. Which JSP code snippet will create this array?

A.   MY_ARRAY = new Array(); <% for ( int i = 0; i <serverArray.length; i++ ) { MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>'; } %>
B.   MY_ARRAY = new Array(); <% for ( int i = 0; i < serverArray.length; i++ ) { MY_ARRAY[${i}] = '${serverArray[i]}'; } %>
C.   MY_ARRAY = new Array(); <% for ( int i = 0; i < serverArray.length; i++ ) { %> MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>'; <% } %>
D.   MY_ARRAY = new Array(); <% for ( int i = 0; i < serverArray.length; i++ ) { %> MY_ARRAY[${i}] = '${serverArray[i]}'; <% } %>

Ans: C

Q.2
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)}

Ans:A,D
   
Q.3
Given tutorial.jsp:
 2. <h1>EL Tutorial</h1>
 3. <h2>Example 1</h2>
 4. <p>
 5. Dear ${my:nickname(user)}
 6. </p>
  
Which, when added to the web application deployment descriptor, ensures that line 5 is included verbatim in the JSP output?

A.   <jsp-config> <url-pattern>*.jsp</url-pattern> <el-ignored>true</el-ignored> </jsp-config>
B.   <jsp-config> <url-pattern>*.jsp</url-pattern> <isELIgnored>true</isELIgnored> </jsp-config>
C.   <jsp-config> <jsp-property-group> <el-ignored>*.jsp</el-ignored> </jsp-property-group> </jsp-config>
D.   <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored>true</el-ignored> </jsp-property-group> </jsp-config>
E.   <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <isElIgnored>true</isElIgnored> </jsp-property-group> </jsp-config>

Ans: D

Q.4
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"]}
Ans: D,E

Q.5
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)}

Ans:A,C,E

Q.6
You have created a web application that you license to real estate brokers.The webapp is highly customizable including the email address of the broker, which is placed on the footer of each page. This is configured as a context parameter in the deployment descriptor:

10. <context-param>

11. <param-name>footerEmail</param-name>

12. <param-value>joe@estates-r-us.biz</param-value>

13. </context-param>

 Which EL code snippet will insert this context parameter into the footer?

A.   <a href='mailto:${footerEmail}'>Contact me</a>
B.   <a href='mailto:${initParam@footerEmail}'>Contact me</a>
C.   <a href='mailto:${initParam.footerEmail}'>Contact me</a>
D.   <a href='mailto:${contextParam@footerEmail}'>Contact me</a>
E.    <a href='mailto:${contextParam.footerEmail}'>Contact me</a>

 Ans: C
  
Q.7
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"]]}

Ans: A,C,E

Q.8
All of your JSPs need to have a link that permits users to email the web master. This web application is licensed to many small businesses, each of which have a different email address for the web master. You have decided to use a context parameter that you specify in the deployment descriptor, like this:

42. <context-param>
43. <param-name>webmasterEmail</param-name>
44. <param-value>master@example.com</param-value>
45. </context-param>
Which JSP code snippet creates this email link?
A.   <a href='mailto:${contextParam.webmasterEmail}'>contact us</a>
B.   <a href='mailto:${applicationScope.webmasterEmail}'>contact us</a>
C.   <a href='mailto:${contextInitParam.webmasterEmail}'>contact us</a>
D.   <a href='mailto:${initParam.webmasterEmail}'>contact us</a>
Ans: D

Q.9
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}

Ans: C
   
Q.10

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>

Ans:  B,E
  
Q.17
Click the Exhibit button.
The Appliance class is a Singleton that loads a set of properties into a Map from an external data source.Assume:
An instance of the Appliance class exists in the application-scoped attribute, appl
The appliance object includes the name property that maps to the value Cobia.
The request-scoped attribute, prop, has the value name.
Which two EL code snippets will display the string Cobia? (Choose two.)


A.   ${appl.properties.name}
B.   ${appl.properties.prop}
C.   ${appl.properties[prop]}
D.   ${appl.properties[name]}
E.    ${appl.getProperties().get(prop)}
Ans: A,C
   
Q.18
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.

Ans: D,E
  
Q.19
Which EL expression evaluates to the request URI?
${requestURI}
${request.URI}
${request.getURI}
 ${request.requestURI}
 ${requestScope.requestURI}
 ${pageContext.request.requestURI}
 ${requestScope.request.requestURI}
Ans: F

Q.20
 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}
Ans: B,F
  
Q.21
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}
Ans: D,E

Q.22
You have built your own light-weight templating mechanism. Your servlets, which handle each request, dispatch the request to one of a small set of template JSP pages. Each template JSP controls the layout of the view by inserting the header, body, and footer elements into specific locations within the template page. The URLs for these three elements are stored in request-scoped variables called, headerURL, bodyURL, and footerURL, respectively. These attribute names are never used for other purposes. Which JSP code snippet should be used in the template JSP to insert the JSP content for the body of the page?
A.   <jsp:insert page='${bodyURL}' />
B.   <jsp:insert file='${bodyURL}' />
C.   <jsp:include page='${bodyURL}' />
D.   <jsp:include file='${bodyURL}' />
E.    <jsp:insert page='<%= bodyURL %>' />
F.    <jsp:include page='<%= bodyURL %>' />
Ans: C

Q.23
Given an EL function foo, in namespace func, that requires a long as a parameter and returns a Map, which two are valid invocations of function foo? (Choose two.)
A.   ${func(1)}
B.   ${foo:func(4)}
C.   ${func:foo(2)}
D.   ${foo(5):func}
E.    ${func:foo("easy")}
F.    ${func:foo("3").name}
Ans : C,F

Q.24
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
Ans:  B

Q.25
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]]}
Ans: B,D,G











Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment