How can a Classic tag handler instruct the container to ignore the remainder of the JSP that invoked the tag? (Choose all that apply.)
(JSP v2.0 pg 2-56)
A. | The | |
B. | The | |
C. | The | |
D. | The |
Which directives and/or standard actions are applicable ONLY within tag files? (Choose all that apply.)
-Option A is valid (pg 1-179).
-Option B is invalid because the page directive is never allowed in a tag file (pg 1-179).
-Option C is invalid because the jsp:body action can appear in EITHER a tag file or JSP.
-Option D is valid (pg 1-121).
-Option E is invalid because the taglib directive can appear in EITHER a tag file or JSP.
A medical website hides selective content from users who are not registered. In place of the hidden content, a message should display to encourage users to register. Given the Simple tag handler snippet:
11. public void doTag() throws JspException, IOException { 12. String level = 13. (String) getJspContext().findAttribute("accountLevel"); 14. if((level == null || "trial".equals(level))) { 15. String price = "?"; // TODO get context param 16. String message = "Content for paying members only.<br/>"+ 17. "<a href="register.jsp">Sign up now for only "+price+"!</a>"; 18. getJspContext().getOut().write(message); 19. } else { 20. getJspBody().invoke(null); 21. } 22. }
At line 15, the price for registration should be retrieved from a context parameter named registrationFee, however there are no methods on JspContext for retrieving context parameters. What can solve this problem?
A. | Retrieve the value with | |
B. | Cast the | |
C. | Retrieve the value with | |
D. | Throw an exception to let the user know that the price could not be found. | |
E. | This is impossible with a Simple tag. A Classic tag must be used. |
-Option A the pageContext variable is only available to Classic tags.
-Option B Correct. We never mentioned this trick and you won’t need to know it for the exam, but it might come in handy in the real world!
-Option C Remember, we’re not looking for an attribute, we’re looking for a context parameter.
- Option D Don’t give up so easily! With determination you can provide a good solution!
-Option E is not impossible, just tricky.
Which Simple tag mechanism will tell a JSP page to stop processing?
(JSP v2.0 section 13.6.1)
A. | Return | |
B. | Return | |
C. | Throw a | |
D. | Throw a |
Which are true about the Classic tag model? (Choose all that apply.)
(JSP v2.0 sections 13.1 and 13.2)
A. | The | |
B. | The | |
C. | The | |
D. | The | |
E. | There are three tag interfaces— |
-Option A is invalid because the Tag interface can support tags with a body, but you can’t iterate or gain access to the body content.
-Option C is invalid because doAfterBody can only return SKIP_BODY or EVAL_BODY_AGAIN.
-Option D is invalid because doStartTag returns SKIP_BODY and EVAL_BODY_INCLUDE.
Which must be true if you want to use dynamic attributes for a Simple tag handler? (Choose all that apply.)
(JSP v2.0 section 13.3 pgs 2-74,75)
A. | Your Simple tag must NOT declare any static tag attributes. | |
B. | Your Simple tag must use the | |
C. | Your Simple tag handler must implement the | |
D. | Your Simple tag should extend the | |
E. | Your Simple tag CANNOT be used with the |
Which is true about tag files? (Choose all that apply.)
(JSP v2.0 section 8.4)
A. | A tag file may be placed in any subdirectory of | |
B. | A tag file must have the file extension of | |
C. | A TLD file must be used to map the symbolic tag name to the actual tag file. | |
D. | A tag file may NOT be placed in a JAR file in the |
Given:
(JSP v2.0 pg. 2-68)
10. public class BufTag extends BodyTagSupport { 11. public int doStartTag() throws JspException { 12. // insert code here 13. } 14. }
Assume that the tag has been properly configured to allow body content.
Which, if inserted at line 12, would cause the JSP code <mytags:mytag>BodyContent</mytags:mytag>
to output BodyContent
?
Which about doAfterBody()
is true? (Choose all that apply.)
(JSP v2.0 pg. 1-152)
A. |
| |
B. |
| |
C. | Assuming no exceptions occur, | |
D. | Assuming no exceptions occur, | |
E. | Assuming no exceptions occur, |
Given a JSP page:
(JSP v2.0 TagSupport API pg 2-64)
1. <%@ taglib prefix="my" uri="/WEB-INF/myTags.tld" %> 2. <my:tag1> 3. <%-- JSP content --%> 4. </my:tag1>
The tag handler for my:tag1
is Tag1Handler
and extends TagSupport.
What happens when the instance of Tag1Handler
calls the getParent
method? (Choose all that apply.)
A. | A | |
B. | The | |
C. | A | |
D. | An |
Which is true about the lifecycle of a Simple tag? (Choose all that apply.)
(JSP v2.0 section 13.6 pgs 2-80/83)
A. | The | |
B. | The | |
C. | The | |
D. | The |
Given:
(JSP v2.0 pg 2-27)
10. public class ExampleTag extends TagSupport { 11. private String param; 12. public void setParam(String p) { param = p; } 13. public int doStartTag() throws JspException { 14. // insert code here 15. // more code here 16. } 17. }
Which, inserted at line 14, would be guaranteed to assign the value of the request-scoped attribute param
to the local variable p
? (Choose all that apply.)
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
|
Which are valid method calls on a PageContext
object? (Choose all that apply.)
(JSP v2.0 pg. 2-23)
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
| |
F. |
|
Which is the most efficient JspContext
method to call to access an attribute that is known to be in application scope?
(JSP v2.0 pg. 2-23)
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
| |
F. |
|
-Option A is invalid because there is no such method.
-Option B is invalid because this method only looks in page scope.
-Option C is invalid because this method would be less efficient than Option D because it first checks the other three scopes.
-Option E is invalid because this method retrieves the attribute; it only tells you which scope it resides..
-Option F is invalid because it would be only the first step in a process that would be much less efficient than Option D.
What is the best strategy, when implementing a custom tag, for finding the value of an attribute whose scope is unknown?
(JSP v2.0 pg. 2-23)
A. | Check all scopes with a single
| |
B. | Check all scopes with a single
| |
C. | Check each scope with calls to
| |
D. | Call | |
E. | None of these will work. |
Given a tag, simpleTag
, whose handler is implemented using the Simple tag model and a tag, complexTag
, whose handler is implemented using the Classic tag model. Both tags are declared to be non-empty and non-tag dependent in the TLD.
(JSP v2.0 7.1.6 pg 1-156)
Which JSP code snippets are valid uses of these tag? (Choose all that apply.)
A. | <my:simpleTag> <my:complexTag /> </my:simpleTag> | |
B. | <my:simpleTag> <%= displayText %> </my:simpleTag> | |
C. | <my:simpleTag> <%@ include file="/WEB-INF/web/common/headerMenu.html" %> </my:simpleTag> | |
D. | <my:simpleTag> <my:complexTag> <% i++; %> </my:complexTag> </my:simpleTag> |
-Option A is correct; a Simple tag may include a Complex tag in the body as long as that tag contains no scripting code.
-Option B is invalid because simple tags cannot have a body that includes a JSP expression tag.
-Option C is correct because the include directive is processed before the body of the simpleTag is converted into a JspFragment; however, the included content must also be non-scripting (which is why this example includes an HTML segment).
-Option D is not invalid because of the complexTag usage (as in Option A), but because the complexTag body has scripting code in it.
Which are true about the Tag File model? (Choose all that apply.)
(JSP v2.0 pg. 1-173)
A. | Each tag file must have a corresponding entry in a TLD file. | |
B. | All directives allowed in JSP pages are allowed in Tag Files. | |
C. | All directives allowed in Tag Files are allowed in JSP pages. | |
D. | The | |
E. | The allowable file extensions for Tag Files are | |
F. | For each attribute declared and specified in a Tag File, the container creates a page-scoped attribute with the same name. |
Which are valid in tag files? (Choose all that apply.)
(JSP v2.0 pg. 1-174)
A. |
| |
B. |
| |
C. |
| |
D. | <%@ variable name-given="date" variable-class="java.util.Date" %> | |
E. | <%@ attribute name="name" value="blank" type="java.lang.String" %> |
Which returns the enclosing tag when called from within a tag handler class? (Choose all that apply.)
(JSP v2.0 pg. 2-53)
Given a web application structure:
(JSP v2.0 pg. 1-176)
/WEB-INF/tags/mytags/tag1.tag /WEB-INF/tags/tag2.tag /WEB-INF/tag3.tag /tag4.tag
Which tags could be used by an appropriate taglib
directive? (Choose all that apply.)
A web application includes many forms for users to fill out and submit. Nothing in the pages indicates that a field is required. Business decided that a red asterisk should be placed preceding the text labels of required fields but the project manager is contending that the background color of required fields be light blue and another department is demanding that the project’s application be consistent with their own, where the text of the labels be bold for required fields.
(JSP v2.0 section 7)
Considering the different perspectives on how required fields could be identified in pages, choose the most maintainable usage of a custom tag.
A. | <cust:requiredIcon/>First Name: <input type="text" name="firstName"/> | |
B. |
| |
C. | <cust:requiredField color="red" symbol="*" label="First Name"/> | |
D. | <cust:required> First Name: <input type="text" name="firstName"/> </cust:required> |
-Option A would work if you knew that the required field would always be marked with a preceding symbol and the only potential change would be the identifier used. Even still, it would be just as simple to use an img tag and swap out a .gif icon in an images directory.
-Option B is the most flexible solution. Your custom tag is given full control for constructing the label and text field and how they should be displayed.
-Option C: specifying a color and symbol in the tag is an unsatisfactory solution, as a change to either of these values would require you to update the values of every tag in every JSP.
-Option D: it would be possible to do things this way but your class implementing the tag would have to parse the body and manipulate it, creating a maintenance nightmare.