Q.1 Consider the following code:
<html><body>
${(5 + 3 + a > 0) ? 1 : 2}
</body></html>
<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.
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 Explanation
Using a letter in an EL statement is valid, and so is the statement’s syntax. So answers c and d are incorrect. Since the condition evaluates to true, the first of the two results will be displayed, and a is the correct answer.
Using a letter in an EL statement is valid, and so is the statement’s syntax. So answers c and d are incorrect. Since the condition evaluates to true, the first of the two results will be displayed, and a is the correct answer.
Q.2 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.
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 Explanation
The web.xml file matches tag libraries with URIs, so answer c is incorrect. Java code is contained in a .java file and methods are invoked from within a JSP (.jsp). Thus, answers a and b are incorrect. A tag library descriptor (.tld) matches function names with names that can be used in JSPs, so answer d is correct. To be more specific, it matches a Java method signature with a class name for use in JSPs.
The web.xml file matches tag libraries with URIs, so answer c is incorrect. Java code is contained in a .java file and methods are invoked from within a JSP (.jsp). Thus, answers a and b are incorrect. A tag library descriptor (.tld) matches function names with names that can be used in JSPs, so answer d is correct. To be more specific, it matches a Java method signature with a class name for use in JSPs.
Q.3 Which of the following variables is not available for use in EL expressions?
a. param
b. cookie
c. header
d. pageContext
e. contextScope
b. cookie
c. header
d. pageContext
e. contextScope
Answer: e Explanation
These implicit variables are similar to others used in JSPs. The param, header, and cookie variables access the same objects as those used in request/response access. The pageContext variable provides access to scope variables. So answers a through d are incorrect. But there’s no such thing as a contextS.
These implicit variables are similar to others used in JSPs. The param, header, and cookie variables access the same objects as those used in request/response access. The pageContext variable provides access to scope variables. So answers a through d are incorrect. But there’s no such thing as a contextS.
Q.4 Which tags tell the web container where to find your TLD file in your filesystem?
a. <taglib-directory></taglib-directory>
b. <taglib-uri></taglib-uri>
c. <taglib-location></taglib-location>
d. <tld-directory></tld-directory>
e. <taglib-name></taglib-name>
b. <taglib-uri></taglib-uri>
c. <taglib-location></taglib-location>
d. <tld-directory></tld-directory>
e. <taglib-name></taglib-name>
Answer: c Explanation
The <taglib-name> and <taglib-uri> elements provide the library’s name and URI, but not its place in filesystem, so b and e are incorrect. There are no <taglib-directory> or <tld-directory tags>, which means answers a and d are incorrect. The <taglib-location> elements specify the directory containing the TLD, starting with /WEB-INF/. Therefore, the answer is c.
The <taglib-name> and <taglib-uri> elements provide the library’s name and URI, but not its place in filesystem, so b and e are incorrect. There are no <taglib-directory> or <tld-directory tags>, which means answers a and d are incorrect. The <taglib-location> elements specify the directory containing the TLD, starting with /WEB-INF/. Therefore, the answer is c.
Q.5 Which two of the following expressions won’t return the header’s accept field?
a. ${header.accept}
b. ${header[accept]}
c. ${header['accept']}
d. ${header["accept"]}
e. ${header.'accept'}
b. ${header[accept]}
c. ${header['accept']}
d. ${header["accept"]}
e. ${header.'accept'}
Answers: b and e Explanation
EL arrays can contain strings as long as they are surrounded by single or double quotes. So c and d will return the accept field, and b won’t. Similarly, the EL property operator (.) can contain a string as long as it isn’t surrounded by quotes. So a will return a value and e will cause an error.
EL arrays can contain strings as long as they are surrounded by single or double quotes. So c and d will return the accept field, and b won’t. Similarly, the EL property operator (.) can contain a string as long as it isn’t surrounded by quotes. So a will return a value and e will cause an error.
6. When writing a TLD, which tags would you use to surround fnName(int num), a Java method declared in a separate class?
a. <function-signature></function-signature>
b. <function-name></function-name>
c. <method-class></method-class>
d. <method-signature></method-signature>
e. <function-class></function-class>
b. <function-name></function-name>
c. <method-class></method-class>
d. <method-signature></method-signature>
e. <function-class></function-class>
Answer: a Explanation
Since EL describes these structures as functions, c and d are incorrect. Also, the function’s
name is contained in <name> tags, not <function-name>, so b is incorrect. Since <function-signature> declares the Java method, a is the correct answer.
Since EL describes these structures as functions, c and d are incorrect. Also, the function’s
name is contained in <name> tags, not <function-name>, so b is incorrect. Since <function-signature> declares the Java method, a is the correct answer.
Q.7 Which of the following method signatures is usable in EL functions? a public static expFun(void)
b. expFun(void)
c. private expFun(void)
d. public expFun(void)
e. public native expFun(void)
c. private expFun(void)
d. public expFun(void)
e. public native expFun(void)
Answer: a Explanation
EL functions must refer to methods with modifiers of public and static. Therefore, a is the only acceptable answer. Similarly, the class containing the method must be public.
EL functions must refer to methods with modifiers of public and static. Therefore, a is the only acceptable answer. Similarly, the class containing the method must be public.
No comments:
Post a Comment